How To Create Regex From Any Letter To A Specific Character
Solution 1:
You can create a group which will match all the words starting from the beginning till the =
. You can then access the regex group as shown here.
Something like: ^(.*?)=
Should yield the following group value: http://someurl.com?someparameter
. If you would like to include the =
, then, just do as follows: ^(.*?=)
Solution 2:
Up front: If you're parsing URLs, you might want to use one of the existing URL parsers or URI.js.
The beginning of a string is denoted by ^
so your RegEx could look like ^([^=]+)
. This matches everything but =
from the beginning of the string. If you only want the part after the ?, try \?([^=]+)
. Note that you'll only get the very first parameter this way.
Have a look at MDN explaining RegExp.
Solution 3:
The use of .*
will cause the regex to back track and use of ()
will create a backreference. So we can use this to capture the given string ^[^=]+=
Solution 4:
This pattern should match until =
:
.+?=
Post a Comment for "How To Create Regex From Any Letter To A Specific Character"