Scala regex and parentheses
up vote
0
down vote
favorite
I have the following string:
tagged.big) AND tagged.medium
I need to extract everything from this string that starts from tagged. and ends with one or more whitespaces or )
This is my current regex pattern:
tagged.[),S]+
From the example string I expect:
tagged.big
tagged.medium
but right now it returns:
tagged.big)
tagged.medium
What am I doing wrong and how to fix it?
regex scala
add a comment |
up vote
0
down vote
favorite
I have the following string:
tagged.big) AND tagged.medium
I need to extract everything from this string that starts from tagged. and ends with one or more whitespaces or )
This is my current regex pattern:
tagged.[),S]+
From the example string I expect:
tagged.big
tagged.medium
but right now it returns:
tagged.big)
tagged.medium
What am I doing wrong and how to fix it?
regex scala
regex101.com/r/LrSZe7/2 Check it out this pattern, if it works, i can explain.
– lucas_7_94
Nov 10 at 17:43
Thanks, this is exactly what I need!
– alexanoid
Nov 10 at 17:47
I found thattagged.big1
returnstagged.big
but should also returntagged.big1
.. and the same fortagged.big2
Could you please check it?
– alexanoid
Nov 10 at 17:50
regex101.com/r/LrSZe7/4 Added .big1 (you can see it at the end of the list) and returns it without problem, re-check in your source program if it works.
– lucas_7_94
Nov 10 at 17:56
thanks, works good right now
– alexanoid
Nov 10 at 17:59
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have the following string:
tagged.big) AND tagged.medium
I need to extract everything from this string that starts from tagged. and ends with one or more whitespaces or )
This is my current regex pattern:
tagged.[),S]+
From the example string I expect:
tagged.big
tagged.medium
but right now it returns:
tagged.big)
tagged.medium
What am I doing wrong and how to fix it?
regex scala
I have the following string:
tagged.big) AND tagged.medium
I need to extract everything from this string that starts from tagged. and ends with one or more whitespaces or )
This is my current regex pattern:
tagged.[),S]+
From the example string I expect:
tagged.big
tagged.medium
but right now it returns:
tagged.big)
tagged.medium
What am I doing wrong and how to fix it?
regex scala
regex scala
asked Nov 10 at 17:35
alexanoid
7,0521177173
7,0521177173
regex101.com/r/LrSZe7/2 Check it out this pattern, if it works, i can explain.
– lucas_7_94
Nov 10 at 17:43
Thanks, this is exactly what I need!
– alexanoid
Nov 10 at 17:47
I found thattagged.big1
returnstagged.big
but should also returntagged.big1
.. and the same fortagged.big2
Could you please check it?
– alexanoid
Nov 10 at 17:50
regex101.com/r/LrSZe7/4 Added .big1 (you can see it at the end of the list) and returns it without problem, re-check in your source program if it works.
– lucas_7_94
Nov 10 at 17:56
thanks, works good right now
– alexanoid
Nov 10 at 17:59
add a comment |
regex101.com/r/LrSZe7/2 Check it out this pattern, if it works, i can explain.
– lucas_7_94
Nov 10 at 17:43
Thanks, this is exactly what I need!
– alexanoid
Nov 10 at 17:47
I found thattagged.big1
returnstagged.big
but should also returntagged.big1
.. and the same fortagged.big2
Could you please check it?
– alexanoid
Nov 10 at 17:50
regex101.com/r/LrSZe7/4 Added .big1 (you can see it at the end of the list) and returns it without problem, re-check in your source program if it works.
– lucas_7_94
Nov 10 at 17:56
thanks, works good right now
– alexanoid
Nov 10 at 17:59
regex101.com/r/LrSZe7/2 Check it out this pattern, if it works, i can explain.
– lucas_7_94
Nov 10 at 17:43
regex101.com/r/LrSZe7/2 Check it out this pattern, if it works, i can explain.
– lucas_7_94
Nov 10 at 17:43
Thanks, this is exactly what I need!
– alexanoid
Nov 10 at 17:47
Thanks, this is exactly what I need!
– alexanoid
Nov 10 at 17:47
I found that
tagged.big1
returns tagged.big
but should also return tagged.big1
.. and the same for tagged.big2
Could you please check it?– alexanoid
Nov 10 at 17:50
I found that
tagged.big1
returns tagged.big
but should also return tagged.big1
.. and the same for tagged.big2
Could you please check it?– alexanoid
Nov 10 at 17:50
regex101.com/r/LrSZe7/4 Added .big1 (you can see it at the end of the list) and returns it without problem, re-check in your source program if it works.
– lucas_7_94
Nov 10 at 17:56
regex101.com/r/LrSZe7/4 Added .big1 (you can see it at the end of the list) and returns it without problem, re-check in your source program if it works.
– lucas_7_94
Nov 10 at 17:56
thanks, works good right now
– alexanoid
Nov 10 at 17:59
thanks, works good right now
– alexanoid
Nov 10 at 17:59
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
In your regex you use tagged.[),S]+
which contains a character class with )
, comma and S
which matches not a whitespace character. The S
also matches a comma and )
so that could be shortened to just S+
. But that would match too much.
To match your values, you could for exampe use a word character w
or add to the character class what you would allow to match:
tagged.w+
Regex demo
That will match
tagged.
Match tagged.w+
Match 1+ word characters
Regex demo
add a comment |
up vote
1
down vote
Final pattern : tagged.[^Ws]+ (You can see a further explanation on the site)
So it follows:
- 'tagged.' : matches any string with start with tagged.
- [^ ]: this matches a single character which is NOT presented on the set.
- [^Ws] : matches a single character which is not a non-word or whitespace
+ : quantifier greedy, matches one or unlimited times the set.
[$]
matches a$
char, not an end of the string..
that is not escaped matches any char, not just a dot.
– Wiktor Stribiżew
Nov 10 at 20:15
Great to know, thanks!
– lucas_7_94
Nov 10 at 20:17
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
In your regex you use tagged.[),S]+
which contains a character class with )
, comma and S
which matches not a whitespace character. The S
also matches a comma and )
so that could be shortened to just S+
. But that would match too much.
To match your values, you could for exampe use a word character w
or add to the character class what you would allow to match:
tagged.w+
Regex demo
That will match
tagged.
Match tagged.w+
Match 1+ word characters
Regex demo
add a comment |
up vote
2
down vote
accepted
In your regex you use tagged.[),S]+
which contains a character class with )
, comma and S
which matches not a whitespace character. The S
also matches a comma and )
so that could be shortened to just S+
. But that would match too much.
To match your values, you could for exampe use a word character w
or add to the character class what you would allow to match:
tagged.w+
Regex demo
That will match
tagged.
Match tagged.w+
Match 1+ word characters
Regex demo
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
In your regex you use tagged.[),S]+
which contains a character class with )
, comma and S
which matches not a whitespace character. The S
also matches a comma and )
so that could be shortened to just S+
. But that would match too much.
To match your values, you could for exampe use a word character w
or add to the character class what you would allow to match:
tagged.w+
Regex demo
That will match
tagged.
Match tagged.w+
Match 1+ word characters
Regex demo
In your regex you use tagged.[),S]+
which contains a character class with )
, comma and S
which matches not a whitespace character. The S
also matches a comma and )
so that could be shortened to just S+
. But that would match too much.
To match your values, you could for exampe use a word character w
or add to the character class what you would allow to match:
tagged.w+
Regex demo
That will match
tagged.
Match tagged.w+
Match 1+ word characters
Regex demo
answered Nov 10 at 18:25
The fourth bird
19.5k71323
19.5k71323
add a comment |
add a comment |
up vote
1
down vote
Final pattern : tagged.[^Ws]+ (You can see a further explanation on the site)
So it follows:
- 'tagged.' : matches any string with start with tagged.
- [^ ]: this matches a single character which is NOT presented on the set.
- [^Ws] : matches a single character which is not a non-word or whitespace
+ : quantifier greedy, matches one or unlimited times the set.
[$]
matches a$
char, not an end of the string..
that is not escaped matches any char, not just a dot.
– Wiktor Stribiżew
Nov 10 at 20:15
Great to know, thanks!
– lucas_7_94
Nov 10 at 20:17
add a comment |
up vote
1
down vote
Final pattern : tagged.[^Ws]+ (You can see a further explanation on the site)
So it follows:
- 'tagged.' : matches any string with start with tagged.
- [^ ]: this matches a single character which is NOT presented on the set.
- [^Ws] : matches a single character which is not a non-word or whitespace
+ : quantifier greedy, matches one or unlimited times the set.
[$]
matches a$
char, not an end of the string..
that is not escaped matches any char, not just a dot.
– Wiktor Stribiżew
Nov 10 at 20:15
Great to know, thanks!
– lucas_7_94
Nov 10 at 20:17
add a comment |
up vote
1
down vote
up vote
1
down vote
Final pattern : tagged.[^Ws]+ (You can see a further explanation on the site)
So it follows:
- 'tagged.' : matches any string with start with tagged.
- [^ ]: this matches a single character which is NOT presented on the set.
- [^Ws] : matches a single character which is not a non-word or whitespace
+ : quantifier greedy, matches one or unlimited times the set.
Final pattern : tagged.[^Ws]+ (You can see a further explanation on the site)
So it follows:
- 'tagged.' : matches any string with start with tagged.
- [^ ]: this matches a single character which is NOT presented on the set.
- [^Ws] : matches a single character which is not a non-word or whitespace
+ : quantifier greedy, matches one or unlimited times the set.
edited Nov 10 at 20:17
answered Nov 10 at 18:03
lucas_7_94
1336
1336
[$]
matches a$
char, not an end of the string..
that is not escaped matches any char, not just a dot.
– Wiktor Stribiżew
Nov 10 at 20:15
Great to know, thanks!
– lucas_7_94
Nov 10 at 20:17
add a comment |
[$]
matches a$
char, not an end of the string..
that is not escaped matches any char, not just a dot.
– Wiktor Stribiżew
Nov 10 at 20:15
Great to know, thanks!
– lucas_7_94
Nov 10 at 20:17
[$]
matches a $
char, not an end of the string. .
that is not escaped matches any char, not just a dot.– Wiktor Stribiżew
Nov 10 at 20:15
[$]
matches a $
char, not an end of the string. .
that is not escaped matches any char, not just a dot.– Wiktor Stribiżew
Nov 10 at 20:15
Great to know, thanks!
– lucas_7_94
Nov 10 at 20:17
Great to know, thanks!
– lucas_7_94
Nov 10 at 20:17
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241648%2fscala-regex-and-parentheses%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
regex101.com/r/LrSZe7/2 Check it out this pattern, if it works, i can explain.
– lucas_7_94
Nov 10 at 17:43
Thanks, this is exactly what I need!
– alexanoid
Nov 10 at 17:47
I found that
tagged.big1
returnstagged.big
but should also returntagged.big1
.. and the same fortagged.big2
Could you please check it?– alexanoid
Nov 10 at 17:50
regex101.com/r/LrSZe7/4 Added .big1 (you can see it at the end of the list) and returns it without problem, re-check in your source program if it works.
– lucas_7_94
Nov 10 at 17:56
thanks, works good right now
– alexanoid
Nov 10 at 17:59