2
I am using this "string?" in regex ^\/(.*)\w+$
It detects values that start like this: /STRINGQUALQUER
would like to catch the STRINGQUALQUER
, what code do I use? I use jQuery.
2
I am using this "string?" in regex ^\/(.*)\w+$
It detects values that start like this: /STRINGQUALQUER
would like to catch the STRINGQUALQUER
, what code do I use? I use jQuery.
3
The regex you have now can be divided into 5 parts to understand what you have and how it works:
^
marks the start of the string.\/
means the character /
(.*)
capture group. Will catch all characters except new lines.\w+
characters of words (letters, numbers and _
)$
end of stringIf you want to get the content after /
just use \/(.*)
. Then omit that the bar has to be at the beginning of the string but tells regex that there has to be a bar before the other characters in the string, using .*
.
2
Good from what I understand you have a string /stringqualquer
and would like to get the value of stringqualquer
without the /
in front. Correct?
If that’s your problem it should solve:
[?<=\/](\w*)
or so:
\/?(\w*)
you can test online here.
My response was based on the response of @Renato Dinhani Conceição, who is here on SO EN.
I just switched the ,
for \/?
and ([0-9]+)
for (\w*)
to meet your need.
I was almost finished writing my reply, I was going to suggest regex101 as well. + 1
Try to use it like this [?<=\/](\w*)
or \/?(\w*)
Browser other questions tagged javascript jquery regex
You are not signed in. Login or sign up in order to post.
What do you mean? What do you mean by "any string"? Your regex says that the first character is
/
, retire^\/
then you don’t have to start with/
. But what do you really want to do? Give examples and you’ll get a better answer and you don’t have to similar questions several times...– Sergio
@Sergio Good afternoon to you! I did not ask similar questions haha, in the other question I needed to get the verification, and now I need to get a value, are of the same context but follow different paths. ANYWAY. I don’t know if Regex can do this, but I get values that way
/stringqualquer
, when I speakstringqualquer
I mean any valid character, and I wish to obtain this value that comes after the/
– Vinícius Lara
Just a question. You’re trying to capture what in fact?
.*
will capture any character, but then you have\w
capturing characters from A-Z and 0-9..*
will already work for the\w
, I don’t understand what it is pro regex catch.– Thomas
I also don’t understand how jQuery is related to the problem.
– Thomas
@Thomas in theory I wanted to take any character.
– Vinícius Lara
i want to capture value with jQuery.
– Vinícius Lara
Could you edit the question and put the part of the code that uses regex? It will help to give a better answer to your case and to be clear the use of jQuery in the problem.
– Thomas
@user3163662 ok! and wants only characters that come from a slash
/
? And you just want to pick strings that start with slash?– Sergio
@user3163662 and by the way where will you use this regex? num
.match()
,.replace()
or another?...– Sergio
I managed to solve this problem?
– Sergio