Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 389 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
REGEX FOR VALID JAVASCRIPT VARIABLE IN 1ST CHARACTER

#1
Why am I so stupid? I need to test one character.
Regex has scared me for so long, I really don't know what I'm doing.
I'm writing a parser, so I'm only testing one character at a time.
the block of code I'm working with "knows" it's about to work on a variable. (or expects to)
For the first character in that variable I need to determine if it's $, _ or abc(a letter).

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

This, does not work. It doesn't match for $
Reply

#2
I'm a bit late here, but this doesn't work for a few reasons.

First, because "$" matches the end of the test string (or the line if you're using the multiline "m" modifier). To match the $ character literally, you need to escape it ("\$").
Second, you're not using character ranges. Your current pattern tries to match a letter, then an underscore, then the end of the string via $ instead of any of those.
Third, it's pretty inefficient. If you're testing the first character of a string, why not just do that and eliminate the unnecessary function call? Just use a caret at the beginning to match the start of a string (opposite of $).

Finally, you don't need the global modifier since you're not looking for multiple (or any) matches. A working (and more efficient) regex pattern is included below.
The $ doesn't need escaping because it's in the range, which treats all characters as literal.


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


I highly recommend

[To see links please register here]

to anyone who uses regular expressions often. It's a great visual tester and has tons of resources and reference for learning. Hell, I still use it weekly. Regex is hard, but it's a valuable skill to have, don't get too discouraged.
Reply

#3
I tried this /([A-Z]_?\$?)+$/ig and it works for myself. I would recommend using the one above mine though being as I didn't really test mine that much o-O
Also I didn't read your question that heavily, too tired to read D:
Reply

#4
I'm not even going to test it, but thanks!
It looks very legit and I would recommend.
BTW, HOW LONG DID IT TAKE FOR YOU TO MAKE THIS?
Reply

#5
I got my issue fixed. thanks
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through