Forum: SDL Trados support
Topic: Regular expression for numbers
Poster: Christian Hackspacher
Post title: Some Examples
Hi!
I am learning Regex at the moment and I found some examples that maybe solve your problem.
[url removed]
Seven-Letter Word Containing "hay"
Search pattern: (?=\b\w{7}\b)\w*?hay\w*
Line Contains both "bubble" and "gum"
Search pattern: ^(?=.*?\bbubble\b)(?=.*?\bgum\b).*
Line Contains "boy" or "buy"
Search pattern: \bb(?:oy|uy)\b
Find Repeated Words, such as "the the"
Search pattern: \b([[:alpha:]]+)[ [:punct:]]+\1
Line does Not Contain "boy"
Search pattern: ^(?!.*boy).*
Line Contains "bubble" but Neither "gum" Nor "bath"
Search pattern: ^(?=.*bubble)(?!.*gum)(?!.*bath).*
Validating a Time
Here's an expression I came up with.
^(?:([0]?\d|1[012])|(?:1[3-9]|2[0-3]))[.:h]?[0-5]\d(?:\s?(?(1)(am|AM|pm|PM)))?$
It matches times in a variety of formats, such as 10:22am, 21:10, 08h55 and 7.15 pm.
Topic: Regular expression for numbers
Poster: Christian Hackspacher
Post title: Some Examples
Hi!
I am learning Regex at the moment and I found some examples that maybe solve your problem.
[url removed]
Seven-Letter Word Containing "hay"
Search pattern: (?=\b\w{7}\b)\w*?hay\w*
Line Contains both "bubble" and "gum"
Search pattern: ^(?=.*?\bbubble\b)(?=.*?\bgum\b).*
Line Contains "boy" or "buy"
Search pattern: \bb(?:oy|uy)\b
Find Repeated Words, such as "the the"
Search pattern: \b([[:alpha:]]+)[ [:punct:]]+\1
Line does Not Contain "boy"
Search pattern: ^(?!.*boy).*
Line Contains "bubble" but Neither "gum" Nor "bath"
Search pattern: ^(?=.*bubble)(?!.*gum)(?!.*bath).*
Validating a Time
Here's an expression I came up with.
^(?:([0]?\d|1[012])|(?:1[3-9]|2[0-3]))[.:h]?[0-5]\d(?:\s?(?(1)(am|AM|pm|PM)))?$
It matches times in a variety of formats, such as 10:22am, 21:10, 08h55 and 7.15 pm.