I have this URL:
http://example.com/createSend/step4_1.aspx?cID=876XYZ964D293CF&snap=true&jlkj=kjhkjh&
And this regex pattern:
cID=[^&]*
Which produces this result:
cID=87B6XYZ964D293CF
How do I REMOVE the "cID="?
Thanks
I have this URL:
http://example.com/createSend/step4_1.aspx?cID=876XYZ964D293CF&snap=true&jlkj=kjhkjh&
And this regex pattern:
cID=[^&]*
Which produces this result:
cID=87B6XYZ964D293CF
How do I REMOVE the "cID="?
Thanks
There is a special syntax in javascript which allows you to exclude unwanted match from the result. The syntax is "?:" In your case the solution would be the following
By using capturing groups:
and then get $1:
With JavaScript, you'll want to use a capture group (put the part you want to capture inside
()
) in your regular expressionGenerally speaking, to accomplish something like this, you have at least 3 options:
substring
of the matchReferences
jsref
-substring
Examples
Given this test string:
These are the matches of some regex patterns:
\d+ cats
->16 cats
(see on rubular.com)\d+(?= cats)
->16
(see on rubular.com)(\d+) cats
->16 cats
(see on rubular.com)16
You can also do multiple captures, for example:
(\d+) (cats|dogs)
yields 2 match results (see on rubular.com)35 dogs
35
dogs
16 cats
16
cats
Here's the Javascript code:
You can either use lookbehind (not in Javascript):
Or you can use grouping and grab the first group: