I need get URI of photo. URI spans multiple lines with delimiters. What should be the right side of the pattern to capture everything up to the uppercase letters with a colon? Such as END:, FN: or N:?
let pattern = "URI:(.*)"
let text = "BEGIN:VCARD\r\nVERSION:3.0\r\nPRODID:-//Apple Inc.//iPhone OS 13.6//EN\r\nN:;John;;;\r\nFN:John\r\nTEL;TYPE=CELL,VOICE,pref:+71234567890\r\nPHOTO;VALUE=URI:https://imgurl.com/download/photo.2A2472\r\n 0C-745E-4B17-AE46-B575B81C9490.afeb521a-9397-484a-8703-3e246b6d526d.19D320\r\n 9E-EC79-48D5-AE65-0E29CF208278\r\nEND:VCARD"
Expected Result is https://imgurl.com/download/photo.2A2472\r\n0C-745E-4B17-AE46-B575B81C9490.afeb521a-9397-484a-8703-3e246b6d526d.19D320\r\n9E-EC79-48D5-AE65-0E29CF208278\r\n
You could use:
(?s)URI(.*?)\s*[A-Z]+:
Regex demo | Swift demo code
Explanation
(?s) Inline modifier, make the dot match a newline
URI Match literally
(.*?) Capture group 1, match any char, as least chars as possible
\s*[A-Z]+: Match 0+ whitespace chars, 1+ uppercase chars A-Z followed by :
Use this pattern:
https?:.*(?=END)
See Demo in PCRE
Related
I'm trying to create a Regex to match numbers, special chars, spaces and a specific whole word ("ICT").
Example for the string:
[Columbia (ICT-59)]
Currently I've this Regex to match the numbers, special chars and spaces:
[\W\s\d]
And this one to for the word "ICT":
(ICT)
How can I match both of this in one Regular expression?
use regex:
/(?<=\[)[a-zA-Z]+\s\(ICT-\d+\)(?=\])/g
or
/^\[[a-zA-Z]+\s\(ICT-\d+\)\]$/g
You can use \w+ at the position of [a-zA-Z], if you want to allow digits and special characters at the position of the Location.
demo:
https://regex101.com/r/ZS0jeO/1
https://regex101.com/r/hpQok3/1
You could capture the part the you want in a capture group right after the opening [ and match the rest of the format.
\[([^()]+?)\s*\(ICT-\d+\)]
\[ Match [
([^()]+?) Capture group 1, match 1+ chars other than ( or ), as few as possible
\s* Match optional whitespace chars
\(ICT-\d+\) Match (ICT- 1+ digits and )
] Match literally
Regex demo
Or matching just a single word using \w+
\[(\w+)\s*\(ICT-\d+\)]
Regex demo
Is it possible to match only the letter from the following string?
RO41 RNCB 0089 0957 6044 0001 FPS21098343
What I want: FPS
What I'm trying LINK : [0-9]{4}\s*\S+\s+(\S+)
What I get: FPS21098343
Any help is much appreciated! Thanks.
You can try with this:
var String = "0258 6044 0001 FPS21098343";
var Reg = /^(?:\d{4} )+ *([a-zA-Z]+)(?:\d+)$/;
var Match = Reg.exec(String);
console.log(Match);
console.log(Match[1]);
You can match up to the first one or more letters in the following way:
^[^a-zA-Z]*([A-Za-z]+)
^.*?([A-Za-z]+)
^[\w\W]*?([A-Za-z]+)
(?s)^.*?([A-Za-z]+)
If the tool treats ^ as the start of a line, replace it with \A that always matches the start of string.
The point is to match
^ / \A - start of string
[^a-zA-Z]* - zero or more chars other than letters
([A-Za-z]+) - capture one or more letters into Group 1.
The .*? part matches any text (as short as possible) before the subsequent pattern(s). (?s) makes . match line break chars.
Replace A-Za-z in all the patterns with \p{L} to match any Unicode letters. Also, note that [^\p{L}] = \P{L}.
To grep all the groups of letters that go in a row in any place in the string you can simply use:
([a-zA-Z]+)
You could use a capture group to get FPS:
\b[0-9]{4}\s+\S+\s+([A-Z]+)
The pattern matches:
\b[0-9]{4} A wordboundary to prevent a partial match, and match 4 digits
\s+\S+\s+ Match 1+ non whitespace chars between whitespace chars
([A-Z]+) Capture group 1, match 1+ chars A-Z
Regex demo
If the chars have to be followed by digits till the end of the string, you can add \d+$ to the pattern:
\b[0-9]{4}\s+\S+\s+([A-Z]+)\d+$
Regex demo
I am trying to match a string the 2nd word after "Vores ref.:" using positive lookbehind. It works in online testers like https://regexr.com/, but my tool Alteryx dont allow quantifiers like + in a lookbehind.
"ABC This is an example Vores ref.: 23244-2234 LW782837673 Test 2324324"
(?<=Vores\sref.:\s\d+-\d+\s+)\w+ is correctly matching the LW78283767, on regexr.com but not in Alteryx.
How can I rewrite the lookahead expression by using quantifiers but still get what I want?
You can use a replacement approach here using
.*?\bVores\s+ref\.:\s+\d+-\d+\s+(\w+).*
Replace with $1.
See the regex demo.
Details:
.*? - any 0+ chars other than line break chars, as few as possible
\bVores - whole word Vores
\s+ - one or more whitespaces
ref\.: - ref.: substring
\s+ - one or more whitespaces
\d+-\d+ - one or more digits, - and one or more digits
\s+ - one or more whitespaces
(\w+) - Capturing group 1: one or more word chars.
.* - any 0+ chars other than line break chars, as many as possible.
You can use a capture group instead.
Note to escape the dot \. to match it literally.
\bVores\sref\.:\s\d+-\d+\s+(\w+)
The pattern matches:
\bVores\sref\.:\s\d+-\d+\s+ Your pattern turned into a match
(\w+) Capture group 1, match 1+ word characters
Regex demo
I'm trying to match all the non whitespace characters after a string in Regex. In this example, I want to match "b" without the whitespaces and the slashes around it:
a: /b/
I tried using (?<=a:)([^\s\/]+) but it doesn't work.
You still need to account for / before b, not just for whitespace.
You may use a \K based regex (if your regex flavor is PCRE/Onigmo/Boost):
a:\s*\/\K[^\s\/]+
See the regex demo.
Also, if you are using a regex engine that supports unknown width lookbehind patterns, you may use
(?<=a:\s*\/)[^\s\/]+
See this regex demo.
Else, you need to capture your substring with parentheses:
a:\s*\/([^\s\/]+)
See this regex demo.
Details
a: - a a: string
\s* - 0+ whitespaces
\/ - a / char
\K - a match reset operator
[^\s\/]+ - 1+ chars other than whitespace and /.
I'm using regex trying to get the first character of a specific word between (.*?)
About Sildenafil Citrate Phosphodiesterase-5 Enzyme Inhibitor
and the regex:
Citrate (.*?)Enzyme
So I get match Phosphodiesterase-5
But I need to get only the first character P
You could use the capturing group to capturing a single non whitespace char (\S) and use word boundaries \b :
\bCitrate (\S).*? Enzyme\b
Regex demo
Changing your regex to Citrate (.).*?Enzyme would be enough. This captures the first character after "Citrate ".
If your environments supports lookaround you try this pattern
(?<=\bCitrate ).(?=.*?Enzyme\b)
(?<=\bCitrate ) - Positive lookbehind, match must be preceded by \bCitrate
. - Match anything expect new line
(?=.*?Enzyme\b) - Positive lookahead, match must be followed by .*?Enzyme\b
Regex Demo