2

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.

1 Answer 1

2

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

Online Demo


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 ancor

Online Demo


Though, as most languages do also have some sort of Split() function, you could decide on researching that and ditch regular expressions.

Sign up to request clarification or add additional context in comments.

3 Comments

As as a mere suggestion, in the first pattern all the quantifiers are optional and could also match an empty line and the pattern will try to explore a match from every position. Depending on what is supported of course, you could mark the start of the match with a word boundary \b[^:\r\n]+$ or a whitespace boundary on the left using (?<!\S)[^:\r\n]+$ for example. +1
Thank for the constructive feedback @TheFourthBird. I'll see to it a little later.
just also realized that MSwords has a wildcard function and adobe acrobat will format w/ certain styles so you can edit certain parts of the documents all at once

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.