|
Too many $. In all the regex engines I use (I don't do PowerShell), $ matches the end of the input string. I forgot that off my original answer, sorry. It should be there to disallow trailing garbage.
Similarly you probably need a ^ at the start to match start of string.
In regex,
* means "0 or any number of occurrences of the previous item"
+ means "1 or more occurrences..."
? means "0 or 1 occurrences..."
. matches any character, so to match a literal period, you need to escape it with \
So your regex should finally be
^[A-Za-z]+\.[A-Za-z]+[A-Za-z0-9]?[0-9]$
only adding whatever delimiters and escapes are required by PowerShell (which should probably be just ' ' around the whole exprerssion).
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Peter, I have tested this as you said:
^[A-Za-z]+\.[A-Za-z]+[A-Za-z0-9]?[0-9]$
I cannot make it fail with any of my inputs, good input and bad input, it returns True and False at all the right places.
I will stress test it again tomorrow.
And I will study all this too.
Many Thanks......
|
|
|
|
|
You're welcome.
And keep studying. Don't just stop because your immediate problem is solved.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
why not this?
^[A-z]+\.[A-z]+\d{1,2}$
|
|
|
|
|
Hello all,
I have a question regarding regex address capture.
I have the following address:
Harald Sturm
Schönstrasse 18a
60311 Frankfurt am Main
I want to split this string into 4 components with 4 different regex to do that.
Name: Harald Sturm. (The whole first line)
Street: Schönstrasse 18a (The whole second line)
ZIP CODE: 60311 (First digital part of the sentence )
Location: Frankfurt am Main (Last part of the sentence)
Question for the regex experts: What would each regex expression for this look like ?
Many thanks in advance.
|
|
|
|
|
|
I don't have a label like name, street etc- I just always have three lines.
The first line always records the full name.
The second line records the street including the house number.
The third line consists of a postal code and city. Thereby
the postal code and the city should be extracted separately.
I would need four single regex rules at last.
Thanks a lot in advance
|
|
|
|
|
Did you try the regex I supplied? At all?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
A few lines of code including one call to String.Split would do that much quicker than a regex.
|
|
|
|
|
You may right, but im using it for a rpa tool, that accept only a regex confirm formula for extracting operations.
|
|
|
|
|
hi!
I'm trying to write regex to get the parent DN. it looks like that:
$rx=[regex]'^CN=.*,((?:(?:OU|CN=).*,)*DC=domain,DC=name)$'
that part which is not working is of course '
((?:(?:OU|CN=).*,)* ' - i don't know how to define all parts that can be 'OU=whatever,' or 'CN=whatever,'
help plz ):
|
|
|
|
|
|
thx but i need independent code... and better understand regex. otherwise i could just use substring function, but I want to understand why my thinking doesn't work
|
|
|
|
|
I am looking to find out how to use letters for wildcard patterns.
Ex: 58596Q5555
Ex: 58596q5555
Q=0-4
q=5-9
I need to add many route patterns utilizing this method and am not sure how to add them. I was not able to find any info relating to this.
|
|
|
|
|
Scenario :
RITM1413432","state":"Open"},{"u_categor>\n","active":"true","request_item":"RITM1413419","state":"Open"},{"u_category"
I have to count how many times that ( "state":"Open" ) has in the paragraph by Regular expression.
Can somebody guide me?
Thanks!
|
|
|
|
|
Looks like a job for JSON[^], not a regex.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Why does e.*?r match eer, rather than er, in the word eerie?
My (clearly erroneous) logic is that .*? matches zero or more of any character and as few as possible, so er (with zero of any character) should be the match, not eer (with one of any character).
|
|
|
|
|
Since the .* pattern says match any char any number of times, any text between an 'e' and an 'r' match. In this case the pattern ? is redundant, since the preceding .* will already have matched everything between a literal 'e' and a literal 'r'. So the pattern is equivalent to e.*r
Keep Calm and Carry On
|
|
|
|
|
|
I am using a software integration platform to connect to a Google calendar and read appointment events. Each event has a small description and phone number in the Summary and I need a regular expression to extract those phone numbers.
The problem is that each person entering an event, formats the phone number differently. Some phone numbers have spaces, or country prefix, and in some cases, there are other (irrelevant) numbers in the Summary also. I don’t mind keeping the country prefix if they enter it, but I do need to detect what’s the phone number.
So, here’s some information on the numbers
- If the user entered a prefix there will be a 357 or 00357 or +357 in the summary.
- After the prefix (if it exists) each phone number will start with 94 or 95 or 96 or 97 or 99.
- Then 6 more numbers will follow.
- There could also be spaces between the numbers
Eventually a correct phone number will be
99123456 or 35799123456 or +35799123456
99 can also be 94 or 95 or 96 or 97
I don’t know if this is too complicated or if it’s even possible to create a regex to correctly extract the phone numbers. Any help is appreciated.
Thanks
|
|
|
|
|
It's a good few years since I wrote RegExps and, even when I did, I could never remember whether ^ was start and $ was end or if it was the other way round.
My totally untested guess is (assuming spaces are only allowed between components and / or at the start or end) is
^\s*((\+|00)?357\s*)?9[4-79]\s*\d{6}\s*$
or allowing spaces between any numbers (and / or at the start or end) is
^\s*((\+|(0\s*){2})?3\s*5\s*7\s*)?9\s*[4-79]\s*(\d\s*){6}$
Note: I'm allowing all whitespace, to just explicitly permit spaces and exclude other white space, change all of the \s patterns to single space chars
I look forward to seeing what someone who actually knows RegExps comes up with to see if I am even remotely close.
Edit: I've just re-read the question - you want to extract the text, not just validate it. What I have written above just validates. A simple way to extract would be to, enclose the whole of the text between ^ and $ in parentheses to get a group. Extract the group and then just drop all spaces. e.g. in Javascript
theGroupThatYouHaveFound.Replace(/\s/g, ''); . An even simpler way would be to use the validation RegExp and then remove spaces from the original string (no messing around with groups).
modified 7-Apr-22 12:58pm.
|
|
|
|
|
Dear friends,
I am new to this forum. I need your expert advise on deriving a regular expression to achieve the following. I am using Editplus' search and replace. I could use Notepad++ as well, if required.
I have some files containing several thousand lines of content. I want to match lines in the content except the ones which start with a number and period (1. or 2. .......... 5000.) or the first 4 alphabets and a period (a. or b. or c. or d.). Any help is greatly appreciated. Thanks in advance.
Diamond Dallas
|
|
|
|
|
Old post but... I think this should work (for anyone who has a similar need). You can change the 1 to 0 if you want to avoid lines that begin with "0." as well. Also note that "aa." (or similar) will be matched/returned, since the request was to specifically avoid lines that start with a SINGLE letter (a, b, c, d) followed by a period. But this is easy to adjust as necessary if multiple letters followed by a period should also be skipped/avoided.
^(?![1-9]+\.|[a-d]\.).+$
|
|
|
|
|
Hello, I have problem with regex. For example I have a pattern for (12-12)(15.15)(H) Message and this format repeats itself. I am reading data from file in this format and I would like to know that is there any way to read until (12-12) pattern repeats itself. I can read it with repeats (12-12)(15.15)(H) Message (13-13)(14.14)(L) Messages . but if there is just one, my regex does not work. Also my message has new lines.
|
|
|
|
|
Hi, I was trying to make a regex that matches only if x is present power of 2 times (n=2). Asked otherwise, make a regex that matches if the length of the string is the power of 2 where the only character in the string is x in this case.
So for example,
xx (2), xxxx (4), xxxxxxxx (8) should match but xxx (3), xxxxxx (6) should not match.
Besides this, I also have a query on the regex I was trying to make:
^((xx)*){2}$
to match xx, xxxx and not xxxxxx but this matches the later (see here). From the debugger also, I cannot understand why last 2 x in 6 x matches with the inner group when we have {2} outside.
|
|
|
|