Really easy regex question (or two) - ORF Forums

Really easy regex question (or two) RSS Back to forum

1

Besides the obvious question ("is there a utility that can take your English words and turn them into a logical regex expression")...

I ask you this: can you help me with building a regex (and understanding how it works - I learn by example) which says:

"match any amount of letters followed by any two numbers followed by any one letter followed by @ followed by anything else"



by Bryon more than 10 years ago
2

@Bryon: As for the tool, I personally prefer the expression builder feature of Expresso (http://www.ultrapico.com/Expresso.htm). Others prefer Regex Coach (http://weitz.de/regex-coach/), try both and see which of them you find more suitable.

As for understanding how regexes work, I recommend this tutorial:

http://www.codeproject.com/KB/dotnet/regextutorial.aspx

And finally, as for the regex, the following should work:

[a-zA-Z]*\d{2}[a-zA-Z]@.*

It means any letters, either upper- or lowercase ([a-zA-Z]), any number of repetitions (*) followed by any number (\d) exactly two times ({2}) followed by any letter ([a-zA-Z]) followed by @ followed by any character (.) any number of repetitions (*).

by Krisztian Fekete (Vamsoft) more than 10 years ago
(in reply to this post)

3

Or, if by "letters" you mean basically any characters BUT numbers, use

\D*\d{2}\D@.*

\D means "not a digit", this will match characters like questionmark (?) or the number sign (#) as well.

by Krisztian Fekete (Vamsoft) more than 10 years ago
4

Wow expresso is exactly what i was looking for - i'll learn this utility

Thanks for the expression and explanation there - the aspects i have trouble with are the placement of the modifiers. For example "*[a-zA-Z]" is what logically makes sense to me in that the letters would modify the wildcard... but i understand how it's actually the * that modifies the group of letters

I'll learn this stuff eventually though :) regex is incredibly powerful if you know how to use it.

Thanks for putting up with all my questions over the years

by Bryon more than 10 years ago
5

You are welcome :) That is what we are here for, so if any further questions arise, ask anytime.

by Krisztian Fekete (Vamsoft) more than 10 years ago

New comment

Fill in the form below to add a new comment. All fields are required. If you are a registered user on our site, please sign in first.

It will not be published.
hnp1 | hnp2