Is there any way to select a string after a specified word?
I found many examples how to select with classic regex:
(?<=^License:\W)(\w.*)$
...but JS regex is not supporting positive look behind.
I would like to match string after word "License:":
License: 1234-YXCMD-12XMDM-XXXCC
Is there any solution? I would like to use it on http://integromat.com, which supports only JS regex format.
Here's a good doc from MDN:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Assertions#Types
So here's something you can do:
let str = "License: 1234-YXCMD-12XMDM-XXXCC"
let regexp = /(?<=License: ).*/
console.log(str.match(regexp)[0]) // get 1234-YXCMD-12XMDM-XXXCC
EDIT: This only works in the newest version of Google Chrome as pointed out by #the fourth bird
Related
I have a challenge getting the desired result with RegEx (using C#) and I hope that the community can help.
I have a URL in the following format:
https://somedomain.com/subfolder/category/?abc=text:value&ida=0&idb=1
I want make two modifications, specifically:
1) Remove everything after 'value' e.g. '&ida=0&idb=1'
2) Replace 'category' with e.g. 'newcategory'
So the result is:
https://somedomain.com/subfolder/newcategory/?abc=text:value
I can remove the string from 1) e.g. ^[^&]+ above but I have been unable to figure out how to replace the 'category' substring.
Any help or guidance would be much appreciated.
Thank you in advance.
Use the following:
Find: /(category/.+?value)&.+
Replace: /new$1 or /new\1 depending on your regex flavor
Demo & explanation
Update according to comment.
If the new name is completely_different_name, use the following:
Find: /category(/.+?value)&.+
Replace: /completely_different_name$1
Demo & explanation
You haven't specified language here, I mainly work on python so the solution is in python.
url = re.sub('category','newcategory',re.search('^https.*value', value).group(0))
Explanation
re.sub is used to replace value a with b in c.
re.search is used to match specific patterns in string and store value in the group. so in the above code re.search will store value from "https to value" in group 0.
Using Python and only built-in string methods (there is no need for regular expressions here):
url = r"https://somedomain.com/subfolder/category/?abc=text:value&ida=0&idb=1"
new_url = (url.split('value')[0] + "value").replace("category", 'newcategory')
print(new_url)
Outputs:
https://somedomain.com/subfolder/newcategory/?abc=text:value
I have already implemented angular multi-select Dropdown. Now I want it to search using RegEx. Like if I have qwertyuiop, and if I wrote w*i than it should suggest me all the entries who contains 'W' and 'I' in the same string.
Do you want to know the whole thing, like how to bind the input of an input field, read the input, create an RegEx out of it, and then use the RegEx as a filter to the list you are showing in your dropdown ?
Or only the RegEx part?
For the part with RegEx:
You should take a look at the Javascript Defintion of RegEx (for example at Mozilla Developer Network ). It has a quite nice functionality.
let input:string = // the value the user typed, like w*i
const regEx = new RegExp(input)
let myDropdownList:string[] = // the list of strings i want to filter
let filteredDropdownList = myDropdownList.forEach((value:string)=>{
return regEx.test(value)
})
What happens here?
You are creating a regular Expressen with new RegExp(someString).
You can optimize it with RegEx flags.
Later you test a string with myRegEx.test(theString). It will return true if the regEx founds at least one match in the string.
I hope this helps you a bit.
warm regards.
I'm trying to create a custom filter in Google Analytic to remove the query parts of the url which I don't want to see. The url has the following structure
[domain]/?p=899:2000:15018702722302::NO:::
I would like to create a regex which skips the first 12 characters (that is until:/?p=899:2000), and what ever is going to be after that replace it with nothing.
So I made this one: https://regex101.com/r/Xgbfqz/1 (which could be simplified to .{0,12}) , but I actually would like to skip those and only let the regex match whatever is going to be after that, so that I'll be able to tell in Google Analytics to replace it with "".
The part in the url that is always the same is
?p=[3numbers]:[0-4numbers]
Thank you
Your regular expression:
\/\?p=\d{3}\:\d{0,4}(.*)
Tested in Golang RegEx 2 and RegEx101
It search for /p=###:[optional:####] and capture the rest of the right side string.
(extra) JavaScript:
paragraf='[domain]/?p=899:2000:15018702722302::NO:::'
var regex= /\/\?p=\d{3}\:\d{0,4}(.*)/;
var match = regex.exec(paragraf);
alert('The rest of the right side of the string: ' + match[1]);
Easily use "[domain]/?p=899:2000:15018702722302::NO:::".substr(12)
You can try this:
/\?p\=\d{3}:\d{0,4}
Which matches just this: ?p=[3numbers]:[0-4numbers]
Not sure about replacing though.
https://regex101.com/r/Xgbfqz/1
I have an url like below and wanted to use RegEx to extract segments like: Id:Reference, Title:dfgdfg, Status.Title:Current Status, CreationDate:Logged...
This is the closest pattern I got [=,][^,]*:[^,]*[,&] but obviously the result is not as expected, any better ideas?
P.S. I'm using [^,] to matach any characters except , because , will not exist the segment.
This is the site using for regex pattern matching.
http://regexpal.com/
The URL:
http://localhost/site/=powerManagement.power&query=_Allpowers&attributes=Id:Reference,Title:dfgdfg,Status.Title:Current Status,CreationDate:Logged,RaiseUser.Title:标题,_MinutesToBreach&sort_by=CreationDate"
Thanks,
You haven't specified what programming language you use. But almost all with support this:
([\p{L}\.]+):([\p{L}\.]+)
\p{L} matches a Unicode character in any language, provided that your regex engine support Unicode. RegEx 101.
You can extract the matches via capturing groups if you want.
In python:
import re
matchobj = re.match("^.*Id:(.*?),Title:(.*?),.*$", url, )
Id = matchobj.group(1)
Title = matchobj.group(2)
i have two possible forms of a URL string
http://www.abcexample.com/landpage/?pps=[Y/lyPw==;id_1][Y/lyP2ZZYxi==;id_2];[5403;ord];
http://www.abcexample.com/landpage/?pps=Y/lyPw==;id_1;unknown;ord;
I want to get out the Y/lyPw== in both examples
so everything before ;id_1 between the brackets
will always come after the ?pps= part
What is the best way to approach this? I want to use the big query language as this is where my data sits
Here is one way to build a regular expression to do it:
SELECT REGEXP_EXTRACT(url, r'\?pps=;[\[]?([^;]*);') FROM
(SELECT "http://www.abcexample.com/landpage/?pps=;[XYZXYZ;id_1][XYZZZZ;id_2];[5403;ord];"
AS url),
(SELECT "http://www.abcexample.com/landpage/?pps=;XYZXYZ;id_1;unknown;ord;"
AS url)
You can use this regex:
pps=\[?([^;]+)
Working demo
The idea behind this regex is:
pps= -> Look for the pps= pattern
\[? -> might have a [ or not
([^;]+) -> store the content up to the first semi colon
So, for your both url this regex will match (in blue) and capture (in green) as below:
For BigQuery you have to use
REGEXP_EXTRACT('str', 'reg_exp')
Quoting its documentation:
REGEXP_EXTRACT: Returns the portion of str that matches the capturing group within the regular expression.
You have to use a code like this:
SELECT
REGEXP_EXTRACT(word,r'pps=\[?([^;]+)') AS fragment
FROM
...
For a working example code you can use:
SELECT
REGEXP_EXTRACT(url,r'pps=\[?([^;]+)') AS fragment
FROM
(SELECT "http://www.abcexample.com/landpage/?pps=;[XYZXYZ;id_1][XYZZZZ;id_2];[5403;ord];"
AS url),
(SELECT "http://www.abcexample.com/landpage/?pps=;XYZXYZ;id_1;unknown;ord;"
AS url)
This regex should work for you
(\w+);id_1
It will extract XYZXYZ
It uses the concept of Group capture
See this Demo