NRGdallas
NRGdallas

Reputation: 395

Regex match everything after parenthesis

I am trying to bulk rename around 10,000 files. I have a tool which can use Regex to do this.

I simply need a regex matching " (" and everything after that (space, parenthesis, everything).

Anyone able to help with this really simple problem real fast?

Upvotes: 2

Views: 10634

Answers (3)

user1726343
user1726343

Reputation:

Parentheses are meta-characters in regex, i.e. they mean something special. If you want to signify a literal character that happens to be a meta-character, you need to escape it using a backslash (\). For example, consider the caret (^), which is a meta-character that matches the beginning of a string.

^abcd
matches strings beginning with the sequence of characters "abcd"

\^abcd
matches the sequence of characters "^abcd"

You can read up on the difference between special and literal characters in regexen and how to escape them here: http://www.regular-expressions.info/characters.html

Upvotes: 1

Jarmund
Jarmund

Reputation: 3205

If you want the open parantheses included in the match:

/ \(.*/

If not, use a positive lookbehind:

/(?<= \().*/

See it in action here: http://regexr.com?32p42

Upvotes: 9

Martin Ender
Martin Ender

Reputation: 44259

You should really check out a tutorial, since this is probably the easiest thing you can do with regex. This should do:

[ ]\(.*

The square brackets are just to visualize the space. They can (but don't have to) be omitted.

Upvotes: 5

Related Questions