I’m having trouble building the correct regex for my string. What I want to do is get all entities from my string; they start and end with '. The entities are identifiable by an amount of numbers and a # in front. However, entities (in this case a phone number starting with #) that don’t start or end with ' should not be matched at all.
I hope someone can help me, or at least tell me that what I want to do isn’t possible in one regex. Thanks 🙂
String:
'Blaa lablalbl balbla balb lbal '#39'blaaaaaaaa'#39' ('#39#226#8218#172#39') blaaaaaaaa #7478347878347834 blaaaa blaaaa'
RegEx:
'[#[0-9]+]*'
Wanted matches:
'#39''#39''#39''#226''#8218''#172''#39'
Found matches:
'#39''#39''#39#226#8218#172#39'<- Needs to be split(if possible in the same RegEx)
Another RegEx:
#[0-9]+
Found matches:
'#39''#39''#39''#226''#8218''#172''#39''#7478347878347834'<- Should not be here 🙁
Language:
C# .NET (4.0)
Assuming you can use lookbehind/lookaheads and that your regexp supports variable length lookbehinds (JGSoft / .NET only)
Should work… Tested it using this site and got these results:
Breaking it down is pretty simple:
So, this pattern will match
#\d+if the text before it is'[#0-9]*and the text after is[#0-9]*'