Reputation: 17
Target:
: (x.S.) xxxx xxxx (xxx xx xx xxxx): Expected xxxxxxx 2021
My regex:
\:.*\r
Adding ^\r
or changing \r
to \n
don't work.
Upvotes: 2
Views: 70
Reputation: 75840
If you can say that your strings always contain two colon's I think I'd go with something along the lines of:
\b[^:\r\n]+$
b
- Word boundary[^:\r\n]+)
- Negated colon, carriage return or newline (one or more) $
- End string ancor If you want to explicitly test for two colon's in your string and return everything after the second one (including possible colons), you might want to use:
^(?:[^:]*:){2}\s*(.*)$
^
- Start string ancor(?:
- Non-capturing group
[^:]*):
- Negated colon zero or more times followed by colon{2}
- Repeat non-capturing group two times\s*
- Zero or more spaces(.*)
- Capturing group holding anything but newlines$
- End string ancorThough, as most languages do also have some sort of Split()
function, you could decide on researching that and ditch regular expressions.
Upvotes: 2