I am looking for a regular expression that will...
Thread poster: Michael Beijer

Michael Beijer  Identity Verified
United Kingdom
Local time: 17:39
Member (2009)
Dutch to English
+ ...
Jul 22, 2012

...find every line starting with a number of words enclosed in parentheses and followed by a number of words.

In the example below, I would like to find only the last line.



(word word)
(word word word word)

(word word)
(word word word)


(word)

(word word word word)

(word word word) word



Any suggestions are more than welcome!

Michael

PS: I'm not sure if this is relevant, but my text contains empty lines.

Incidentally, is there any program that can come up with the regular expression for me automatically if I feed it a sample input and output?



[Edited at 2012-07-22 02:27 GMT]


 

Rossana Triaca  Identity Verified
Uruguay
Local time: 13:39
Member (2002)
English to Spanish
I'm not sure I see the difficulty... Jul 22, 2012

Do you need to select the whole line? Or just find it?

If it's the later, a simple \)\s\w would work (finds the end parenthesis, a whitespace character -space, tab etc.- and an alphanumeric character).

But this seems too simple, perhaps you have a more complex format? If you need to select the whole line, \(.*\)\s\b.*\b works but its too tailored to your example... (finds anything between parenthesis followed by a whitespace followed by "whole" words).

Hope it helps!

[Edited at 2012-07-22 03:20 GMT]


 

Michael Beijer  Identity Verified
United Kingdom
Local time: 17:39
Member (2009)
Dutch to English
+ ...
TOPIC STARTER
Hello Rossana, Jul 22, 2012

Your second expression


\(.*\)\s\b.*\b


does the trick!

It's a little hard to explain, but the reason I need to do this is that I am working on a very large glossary in CSV format (with 5 columns: Dutch, Dutch Definition, English, second English, third English term), and I need to isolate only the lines that have something like '(word word word) word' on them, because these need to be fixed.

In a previous step, I used parentheses in a Find and Replace operation (it's a long story...), and in doing so inadvertently messed up sth that now needs to be fixed. I hope this makes at least SOME sense. Anyway, I had been scrolling down through the whole thing manually, trying to spot all of these lines visually, but with your regex I can now just find them all in one fell swoop and fix them, which will save me a LOT of time.

Thanks!

Michael


 

Rossana Triaca  Identity Verified
Uruguay
Local time: 13:39
Member (2002)
English to Spanish
Glad it helped! Jul 22, 2012

Remember that regex serches can preserve the match, so if you need to "move" that parenthesis within the line it can also be automatedicon_smile.gif

Best of lucks with that glossary!


 


To report site rules violations or get help, contact a site moderator:


You can also contact site staff by submitting a support request »

I am looking for a regular expression that will...

Advanced search






SDL Trados Studio 2017 only €435 / $519
Get the cheapest prices for SDL Trados Studio 2017 on ProZ.com

Join this translator’s group buy brought to you by ProZ.com and buy SDL Trados Studio 2017 Freelance for only €435 / $519 / £345 / ¥63000 You will also receive FREE access to Studio 2019 when released.

More info »
WordFinder Unlimited
For clarity and excellence

WordFinder is the leading dictionary service that gives you the words you want anywhere, anytime. Access 260+ dictionaries from the world's leading dictionary publishers in virtually any device. Find the right word anywhere, anytime - online or offline.

More info »



Forums
  • All of ProZ.com
  • Term search
  • Jobs
  • Forums
  • Multiple search