Skip to content

why doesn't a pattern with / at the beginning and end work as I would expect? #2463

Answered by BurntSushi
zusage asked this question in General
Discussion options

You must be logged in to vote

This is why providing the actual command you're running is so critical. In this case, it has nothing to do with your regex. Instead, here you are putting slashes at the beginning and end of your regex pattern. I don't know why. Just remove them and it works:

$ echo "foo(var, var2, var3);" | rg 'foo\((\w+(?:,\s*\w+)*)\);'
foo(var, var2, var3);

If there is some documentation that led you to putting slashes in your regex pattern, I'd love to fix it. Could you please point me to where you thought it was necessary to use slashes?

Replies: 6 comments 9 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@zusage
Comment options

Answer selected by BurntSushi
Comment options

You must be logged in to vote
1 reply
@BurntSushi
Comment options

Comment options

You must be logged in to vote
2 replies
@ltrzesniewski
Comment options

@BurntSushi
Comment options

Comment options

You must be logged in to vote
5 replies
@BurntSushi
Comment options

@drazde
Comment options

@BurntSushi
Comment options

@BurntSushi
Comment options

@drazde
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants