This question already has answers here:
Using regular expressions to parse HTML: why not?
(18 answers)
Closed 8 years ago.
Can anyone give me the pattern of the regex to get all the local images ONLY. :(
I'm using the code below but it includes the image links.
Regex rgx = new Regex("[^\\/:*?\"<>|]+\\.(?i)(jpg|png|gif|bmp)", RegexOptions.IgnoreCase);
input:
http://dl9.glitter-graphics.net/pub/846/846279rr8zhg26y6.gif
images/strawberries.jpg
output:
846279rr8zhg26y6.gif
strawberries.jpg
I don't want the 846279rr8zhg26y6.gif
If your input strings are bounded somehow (e.g. inside ""s or at the start of the input string) then things are easier, and if the input has a semantic context of being a (relative or absolute) URL, and you only want relative URLs, then easier still.
I would however note that the extension part should probably be jpe?g rather than just jpg and I do wish people would never ever use a bmp on a webpage!
Related
This question already has answers here:
How to use regex to get file extension?
(3 answers)
Closed 6 months ago.
We have a custom field defined in data studio which extracts and returns the file extension from a string in this case it is from the event label.
I have been using the below with some success
REGEXP_EXTRACT(Event Label, '\\.([\\w\\.-]+)$')
However I'm finding if the string contains multiple periods its including that aswell
Eg it's also extracting text like
07.21.pdf
7.22.PDF
07.21.docx
docx.pdf
How can I tweak my regex to only include from the last period and ignore any earlier.
You could try replacing [\\w\\.-] with [^\\.]
\\.([^\\.]+)$
[^\\.] will match everything except for ., so the match will not be able to contain dots inside.
The full formula would look like this:
REGEXP_EXTRACT(Event Label, '\\.([^\\.]+)$')
This question already has answers here:
How to edit all lines in Visual Studio Code
(9 answers)
Closed 3 years ago.
So essentially someone on our dev team made a bit of a big issue where they had changed all of the build actions on .csproj files and we are thinking of the easiest way to change them back.
We want to use regex to open all the csproj files via VSCode. The format to open multiple files in file explorer is
"filename" "filename1" "filename2"
my list is
com.Console.job1.csproj
com.Console.job2.csproj
com.Console.job3.csproj
com.Console.job4.csproj
my current regex
(.+)\n
then my regex to replace is
"$1"\s
which doesnt work at all
You can use this regex :
To locate pattern
([^\s]+)(\n)?
To replace :
"$1"
keep in mind the replace pattern contains a space at its end
Demo :
Here
This question already has answers here:
Find numbers after specific text in a string with RegEx
(3 answers)
Closed 3 years ago.
I have string like this which looks like a url
mainpath/path2/abc/PI 6/j
From the string I need to get the number along with PI
Main problem is the position of PI part wont be always the same. Sometimes it could be at the end. Sometimes at the middle.
So how can I get that number extracted using regex?
I'm really stucked with this
It's as simple as using the RegEx Tool. A Regular Expression of /PI (\d+) and the Output Method of "Parse" should do the trick.
If you're using Alteryx... suppose your field name is [s] and you're looking for [f] (in your example the value of [f] is "PI")... then you could have a Formula tool that first finds /PI by first creating a new field [tmp] as:
SubString([s],FindString([s],"/"+[f])+1)
and then creating the field you're after [target]:
SubString([tmp],0,FindString([tmp],"/"))
From there run [target] through a "Text to Columns" tool to split on the space, which will give you "PI" and "6".
This question already has answers here:
C# Regex find string between two strings with newLine
(3 answers)
Closed 3 years ago.
The Problem
I have a hobby project that has the aim to sync multiple calendars by requesting the ics file from persons calendars in a group, for the optimal time to plan a meeting. Some sort of lazy way to schedule meetings :)
But i got stuck on reading the ics file for two reasons:
I don't really understand Regex.
And i don't know how to achieve my goal with string manipulation.
The ics file is already structured, so i know that i want to start from BEGIN:VEVENT and gather the that text down to END:VEVENT.
I want every event to in a later stage become a class so i can read the data and come up with a decision to present for the end user.
Background
I tried the regex expression: BEGIN:VEVENT(?:[\w\s\:\#\.\;\-\=\ä\å\ö\\\,\/\#]*)END:VEVENT but that is not a very valid approach. Because it gathers all of the the events and does not divide them into separate groups.
I have been using regexer.com to test my regex expression.
Not code but what i work on
This is some of the text from the ics file:
BEGIN:VEVENT
DTSTART:20121220T180000Z
DTEND:20121220T190000Z
DTSTAMP:20190503T064840Z
UID:SomeHash#google.com
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;CN=Name;X-NUM-GUESTS=0:mailto:MailAddress
CREATED:20121212T061002Z
LAST-MODIFIED:20121212T061003Z
LOCATION:ALocation
SEQUENCE:1
STATUS:TENTATIVE
SUMMARY:SomeText
TRANSP:OPAQUE
CATEGORIES:http://schemas.google.com/g/2005#event
END:VEVENT
BEGIN:VEVENT
DTSTART:20121213T143000Z
DTEND:20121213T153000Z
DTSTAMP:20190503T064840Z
UID:SomeHash#google.com
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;CN=Name;X-NUM-GUESTS=0:mailto:MailAddress
CREATED:20121212T061146Z
LAST-MODIFIED:20121212T061146Z
LOCATION:ALocation
SEQUENCE:1
STATUS:TENTATIVE
SUMMARY:SomeText
TRANSP:OPAQUE
CATEGORIES:http://schemas.google.com/g/2005#event
END:VEVENT
Desired outcome
Is to get a array of matches with the string text so i can split it even more and create classes.
Disclaimer
As this is a hobby project i want to take on a challenge and not use a plugin or helping library. But links to these are appreciated if i can see how they solve the problem.
try using
BEGIN:VEVENT([\s\S]*?)END:VEVENT
I use Regex101.com for regex, Hope this helps
Regular expressions are usually a good fit for extracting text. But in this simple case you could try something like this:
var preambleLenght = "BEGIN:VEVENT\r\n".Length;
var text = ics.Substring(preambleLenght, ics.LastIndexOf("\r\nEND:VEVENT") - preambleLenght);
This question already has answers here:
What special characters must be escaped in regular expressions?
(13 answers)
Closed 5 years ago.
I 've a File structure "solution/"
Need a reg exp to match all the files under "solution/" Excluding .img files in the path "solution/tree/changes/sample.img"
I tried below it but of not worked
^solution\/tree\/changes\/((?!.img).)*$
Thanks in advance
You did not mention language, but this should work
^solution\/tree\/changes\/(?!.*\.img).*$
see regex101 demo: https://regex101.com/r/Y7znBy/1
Important! You need to set multilineflag
#Fallenhero My Exact requirement is I 've following file structure
solution/moon/
solution/tree/anomoly/
solution/tree/enquiry/
solution/tree/changes/space.img
solution/tree/changes/mine.txt
I've to parse a json file as input with regular expression to copy all the files in the above structure except solution/tree/changes/space.img
JSON Input which I've tried but didn't work
"^solution\/(?!tree\/).*\/*",
"^solution\/tree\/(?!changes\/).*\/*",
"^solution\/tree\/changes\/((?!.img).)*$"
Could you please provide your ideas