When I use the following expression in notepad++ it does successfully selects line that contains the word "post" in it, but when I use it in winautomation it doesn't work :(
^.*post.*$
Can someone please tell me what would be some alternative regex expression by which I can select lines that contains the word "post"
Also I am not sure if this would help or not but here is a sample expression that works in winautomation, I use it to parse urls off XML files, is this a different regex format than the one above?
(?<=<loc>).*?(?=</loc>)
What you are trying to do with ^.*post.*$ is match any character any number of times followed by post word followed by any character any number of times.
A logical way would be to lookahead if post is present and select whole line. This is done by following regex.
Regex: (?=.*post)^.*$
Explanation:
(?=.*post) would lookahead for any number of characters any number of time followed by word post.
^.*$ if previous assertion is true then regex will match whole line.
Regex101 Demo
Related
I've looked through Regex Last occurrence? but cannot get the regex to work for my example string ("https://www.fakesite.com test one"). I need to return the last character of the website name only (or the position). I have the expressions for both capturing the site and obtaining the last character but cannot get the expression to get the right look behind.
(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]
{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|
(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,}) <- Regular Expression for website
(?=.?$). <- Regular Expression for retrieving last character
I've been using https://regex101.com/ to try and find, but no luck.
How can I retrieve the last character or position?
--Edit--
How can I retrieve just the last character of any string? (I need just the letter 'r' in System Engineer). 'System Engineer' is dynamic.
"for the position of System Engineer located in"
(?<=position of )(.*)(?= located) <- regex to capture System Engineer between words 'position of' and 'located'
You may try the below regex. The below regex will check for valid url address as well as will get you the last character of your url.
https?:\/\/(?:www\.)?[-a-zA-Z0-9#:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}(\w)\b(?:[-a-zA-Z0-9()#:%_\+.~#?&\/\/=]*)
Explanation of the above regex:
https?:\/\/(?:www\.)?[-a-zA-Z0-9#:%._\+~#=]{1,256} - Matches the http/https:// part of the regex along with www and the domain name before the first ..
[a-zA-Z0-9()]{1,6} - This part matches the last of the url part.
(\w) - Represents a capturing group capturing the last character of the url. You may use ([a-zA-Z0-9]) manually if you don't want to include _.
\b(?:[-a-zA-Z0-9()#:%_\+.~#?&\/\/=]*) - Matches the rest part of the url like .uk or .in, etc. zero or more times.
You can find the demo of the above regex in here.
Reference: The regex for matching the valid url is taken from this answer.
If you want to get amendments in your regex; just add [a-zA-Z] after your regex. You can find the demo here.
I have the following cases that should match with a regular expression, I've tried several combinations and have read a lot of answers but still no clue on how to solve it.
the rule is, find any combination of . inside a quoted string, atm I have the following regexp
\"\w*((..)|(.))\w*\"
that covers most of the cases:
mmmas"A.F"asdaAA
196.34.45.."asd."#
".add"
sss"a.aa"sss
".."
"a.."
"a..a"
"..A"
but still having problems with this one:
"WERA.HJJ..J"
I've been testing the regpexp in the http://regexr.com/ site
I will really appreciate any help on this
Change your regex to
\"\w*(\.+\w*)+\"
Update: escape . to match the dot and not any character
demo
From the question, it seems that you need to find every occurrence of one or more dot (along with optional word characters) inside a pair of quotes. The following regex would do this:
\"\w*(\.+\w*)+\"
In "WERA.HJJ..J", you have some word characters followed by a dot which is followed by a sequence of word characters again followed by dot and word characters. Your regex would match one or two dots with a pair of optional word character blocks on either sides only.
The dots in the regex are escaped to avoid them being matched against any character, since it is a metacharacter.
Check here.
I have a custom tag of Part of speech. I want to check if they are consecutive.
My string is
<pronouns></pronouns><pronouns></pronouns><verbs></verbs><determiners></determiners><noun></noun>
Eg. If i use this regex (<pronouns><\/pronouns>)\1{1} it gives me two pronoun tags consecutively
**<pronouns></pronouns><pronouns></pronouns>**<verbs></verbs><determiners></determiners><noun></noun>
and if i use this regex (<pronouns><\/pronouns><verb><\/verb>)\1{0}
it gives me one occurrence of pronoun and verb tag and if i modify it to (<pronouns><\/pronouns><verb><\/verb>)\1{1} it will give me two consecutive occurrence of pronoun and verb tag.
Problem is this if there is any text between the tag it fails to match if it is consecutive
<pronouns>Hello</pronouns><pronouns>Hi</pronouns><pronouns>Hi</pronouns><verbs>Ok</verbs><determiners>the</determiners><noun>people</noun>
match fails for above if you use Previous Regex.
How can I match the regex with text with the previous conditions and also get the text captured between the consecutive tags tags.
As previously stated - this isn't crystal clear... But if I understand it correctly you want to match if there are two consecutive pair of pronoun-tags, no matter what their text content is.
If that's correct, you could try
(?:<(pronouns)>.*?<\/\1>){2}
It matches the first pronoun-tag, capturing the the name. Then it matches any text up to the closing tag. Matches that and then repeats the same pattern again.
Check it out here at regex101.
The input I can get might be
/DemoSystems/DemoFramework/MyRepo/MyModule/tags/2015_02_22
or
/DemoSystems/DemoFramework/MyRepo/MyModule/tags/2015_02_22/Demo.Tests/AverageTests.cs
I need to extract in both cases.
/DemoSystems/DemoFramework/MyRepo/MyModule/tags/2015_02_22
Regex:
^(.*?)tags
is matching till
/DemoSystems/DemoFramework/MyRepo/MyModule/tags
And added complexity is that 2015_02_22 can be anything. A mix of number alphabets and whitespaces. Basically depends on developer. So in other words I have to match till 'tags' + the next folder after it.
Any pointers?
You can use:
.*?tags\/[^\/]+
It will match anything from the start of the line until the word tags, the / after the word tags and the following characters until another / (excluding that) or the end of the string.
Online demo
I'm trying to match a single string out of an email using regex. The email pattern looks like:
name.name.someid#mail.domain.com
And I would like to grab the 'someid' section. Meaning I need to match everything before the '#' and after the last period.
I can match everything before the '#' with (^[^#]+) however I can't effectively combine it in the regex statement to evaluate only after the last period (I can only get it to match after the first period).
Any pointers would be great, thanks!
Use a positive lookahead:
/[^.]+(?=#)/
Here's a demo: http://regex101.com/r/sW7sR3
/\.([^.#]+)#/
Without using lookarounds, this matches anything that's not an # or . that comes after a . and before #.