Using RegEX to get a certain value

2

Am I using this "string?" in regex ^\/(.*)\w+$ it detects values that start like this: /STRINGQUALQUER would like to get STRINGQUALQUER , what code do I use? I use jQuery.

    
asked by anonymous 29.11.2014 / 16:39

2 answers

3

The regex you have now can be broken down into 5 parts to see what it has and how it works:

  • ^ marks the beginning of the string.
  • \/ means /
  • % with% catch group. It will catch all the characters except for new lines.
  • (.*) word characters (letters, numbers and \w+ )
  • _ end of string

If you want to catch the content after $ just use / . It omits that the slash has to be at the beginning of the string but tells the regex that there must be a slash before the other characters of the string, using \/(.*) .

Example this link.

    
29.11.2014 / 17:18
2

Well I understand you have a string /stringqualquer and would like to get the value of stringqualquer without the / up front. Correct?

If this is your problem this should resolve:

[?<=\/](\w*)

or so:

\/?(\w*)

You can test online here .

My response was based on the response from @Renato Dinhani Conceição, which is here at SO PT .

I just switched , to \/? and ([0-9]+) to (\w*) to meet your need.

    
29.11.2014 / 17:12