Click here to Skip to main content
15,444,721 members
Home / Discussions / Regular Expressions
   

Regular Expressions

 
QuestionRegular Expressions RegEx - Wildcards for route patterns Pin
Member 1563258311-May-22 6:05
MemberMember 1563258311-May-22 6:05 
QuestionDoubt in Regular Expression Pin
Member 156250644-May-22 20:09
MemberMember 156250644-May-22 20:09 
AnswerRe: Doubt in Regular Expression Pin
Richard Deeming4-May-22 21:17
mveRichard Deeming4-May-22 21:17 
QuestionRegex Lazy Match Zero or More Times (*?) Pin
Member 155940887-Apr-22 2:52
MemberMember 155940887-Apr-22 2:52 
AnswerRe: Regex Lazy Match Zero or More Times (*?) Pin
k50547-Apr-22 4:17
mvek50547-Apr-22 4:17 
GeneralRe: Regex Lazy Match Zero or More Times (*?) Pin
Member 155940887-Apr-22 10:45
MemberMember 155940887-Apr-22 10:45 
Questiondetect and extract phone numbers Pin
aristosv30-Mar-22 23:02
Memberaristosv30-Mar-22 23:02 
AnswerRe: detect and extract phone numbers Pin
jsc427-Apr-22 6:46
professionaljsc427-Apr-22 6:46 
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
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.

QuestionMatch all lines except lines beginning with numbers or a few alphabets Pin
Diamond Dallas30-Mar-22 3:06
MemberDiamond Dallas30-Mar-22 3:06 
Questionfinding repetead pattern Pin
Member 1556742215-Mar-22 6:19
MemberMember 1556742215-Mar-22 6:19 
QuestionMatch if token exists only power of n times; Match if length of string is power of n Pin
Member 1556219610-Mar-22 9:35
MemberMember 1556219610-Mar-22 9:35 
AnswerRe: Match if token exists only power of n times; Match if length of string is power of n Pin
Richard Deeming10-Mar-22 20:58
mveRichard Deeming10-Mar-22 20:58 
GeneralRe: Match if token exists only power of n times; Match if length of string is power of n Pin
Member 1556219611-Mar-22 2:23
MemberMember 1556219611-Mar-22 2:23 
Questionregex for one Capital Pin
Member 140883235-Mar-22 10:01
MemberMember 140883235-Mar-22 10:01 
AnswerRe: regex for one Capital Pin
OriginalGriff5-Mar-22 10:09
mveOriginalGriff5-Mar-22 10:09 
GeneralRe: regex for one Capital Pin
Member 140883235-Mar-22 10:22
MemberMember 140883235-Mar-22 10:22 
GeneralRe: regex for one Capital Pin
OriginalGriff5-Mar-22 20:20
mveOriginalGriff5-Mar-22 20:20 
GeneralRe: regex for one Capital Pin
Richard Andrew x646-Mar-22 4:41
professionalRichard Andrew x646-Mar-22 4:41 
GeneralRe: regex for one Capital Pin
OriginalGriff6-Mar-22 5:38
mveOriginalGriff6-Mar-22 5:38 
QuestionRegex with condition? Should be easy Pin
Cp Divers21-Feb-22 4:44
MemberCp Divers21-Feb-22 4:44 
QuestionRe: Regex with condition? Should be easy Pin
Eddy Vluggen21-Feb-22 9:48
professionalEddy Vluggen21-Feb-22 9:48 
AnswerRe: Regex with condition? Should be easy Pin
Peter_in_278021-Feb-22 12:35
professionalPeter_in_278021-Feb-22 12:35 
QuestionRe: Regex with condition? Should be easy Pin
Richard MacCutchan21-Feb-22 21:10
mveRichard MacCutchan21-Feb-22 21:10 
AnswerRe: Regex with condition? Should be easy Pin
Peter_in_278021-Feb-22 23:03
professionalPeter_in_278021-Feb-22 23:03 
GeneralRe: Regex with condition? Should be easy Pin
Richard MacCutchan23-Feb-22 3:03
mveRichard MacCutchan23-Feb-22 3:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.