Regex: match not-words except token
up vote
-3
down vote
favorite
i am trying to match all not-words except ";;;"
in a string, but i don't succeed. The not-words are unknown beforehand. Please see an example as follows:
Teststring:
ab-cd ef;;;gh;ij;;;
Result:
abcdef;;;ghij;;;
Does anybody know a smart solution for that?
Thank you very much!
regex regex-negation regex-lookarounds
add a comment |
up vote
-3
down vote
favorite
i am trying to match all not-words except ";;;"
in a string, but i don't succeed. The not-words are unknown beforehand. Please see an example as follows:
Teststring:
ab-cd ef;;;gh;ij;;;
Result:
abcdef;;;ghij;;;
Does anybody know a smart solution for that?
Thank you very much!
regex regex-negation regex-lookarounds
4
"Not-words"? Could you clarify what a "not-word" is?
– connectyourcharger
Nov 22 at 13:06
By not-words i mean any non alphanumeric character. I want to replace all of those except ";;;"
– user10690376
Nov 22 at 13:19
add a comment |
up vote
-3
down vote
favorite
up vote
-3
down vote
favorite
i am trying to match all not-words except ";;;"
in a string, but i don't succeed. The not-words are unknown beforehand. Please see an example as follows:
Teststring:
ab-cd ef;;;gh;ij;;;
Result:
abcdef;;;ghij;;;
Does anybody know a smart solution for that?
Thank you very much!
regex regex-negation regex-lookarounds
i am trying to match all not-words except ";;;"
in a string, but i don't succeed. The not-words are unknown beforehand. Please see an example as follows:
Teststring:
ab-cd ef;;;gh;ij;;;
Result:
abcdef;;;ghij;;;
Does anybody know a smart solution for that?
Thank you very much!
regex regex-negation regex-lookarounds
regex regex-negation regex-lookarounds
edited Nov 22 at 13:06
Poul Bak
5,42831132
5,42831132
asked Nov 22 at 13:03
user10690376
1
1
4
"Not-words"? Could you clarify what a "not-word" is?
– connectyourcharger
Nov 22 at 13:06
By not-words i mean any non alphanumeric character. I want to replace all of those except ";;;"
– user10690376
Nov 22 at 13:19
add a comment |
4
"Not-words"? Could you clarify what a "not-word" is?
– connectyourcharger
Nov 22 at 13:06
By not-words i mean any non alphanumeric character. I want to replace all of those except ";;;"
– user10690376
Nov 22 at 13:19
4
4
"Not-words"? Could you clarify what a "not-word" is?
– connectyourcharger
Nov 22 at 13:06
"Not-words"? Could you clarify what a "not-word" is?
– connectyourcharger
Nov 22 at 13:06
By not-words i mean any non alphanumeric character. I want to replace all of those except ";;;"
– user10690376
Nov 22 at 13:19
By not-words i mean any non alphanumeric character. I want to replace all of those except ";;;"
– user10690376
Nov 22 at 13:19
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You can use the following regex to get all the parts of the string, you want to keep:
/w+(?:;{3})?/g
It matches any number of Word chars
, followed by a non capturing Group matching 3 semi colons
. This is optional.
You can then create the result by joining all the matches
to a string.
Thank you. Can you think of a way to match all the W characters (except ;;;) in order to replace them?
– user10690376
Nov 22 at 14:21
Here you get 'what you want', not 'what you don't want', so Theres nothing that should be replaced.
– Poul Bak
Nov 22 at 14:29
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You can use the following regex to get all the parts of the string, you want to keep:
/w+(?:;{3})?/g
It matches any number of Word chars
, followed by a non capturing Group matching 3 semi colons
. This is optional.
You can then create the result by joining all the matches
to a string.
Thank you. Can you think of a way to match all the W characters (except ;;;) in order to replace them?
– user10690376
Nov 22 at 14:21
Here you get 'what you want', not 'what you don't want', so Theres nothing that should be replaced.
– Poul Bak
Nov 22 at 14:29
add a comment |
up vote
0
down vote
You can use the following regex to get all the parts of the string, you want to keep:
/w+(?:;{3})?/g
It matches any number of Word chars
, followed by a non capturing Group matching 3 semi colons
. This is optional.
You can then create the result by joining all the matches
to a string.
Thank you. Can you think of a way to match all the W characters (except ;;;) in order to replace them?
– user10690376
Nov 22 at 14:21
Here you get 'what you want', not 'what you don't want', so Theres nothing that should be replaced.
– Poul Bak
Nov 22 at 14:29
add a comment |
up vote
0
down vote
up vote
0
down vote
You can use the following regex to get all the parts of the string, you want to keep:
/w+(?:;{3})?/g
It matches any number of Word chars
, followed by a non capturing Group matching 3 semi colons
. This is optional.
You can then create the result by joining all the matches
to a string.
You can use the following regex to get all the parts of the string, you want to keep:
/w+(?:;{3})?/g
It matches any number of Word chars
, followed by a non capturing Group matching 3 semi colons
. This is optional.
You can then create the result by joining all the matches
to a string.
answered Nov 22 at 13:25
Poul Bak
5,42831132
5,42831132
Thank you. Can you think of a way to match all the W characters (except ;;;) in order to replace them?
– user10690376
Nov 22 at 14:21
Here you get 'what you want', not 'what you don't want', so Theres nothing that should be replaced.
– Poul Bak
Nov 22 at 14:29
add a comment |
Thank you. Can you think of a way to match all the W characters (except ;;;) in order to replace them?
– user10690376
Nov 22 at 14:21
Here you get 'what you want', not 'what you don't want', so Theres nothing that should be replaced.
– Poul Bak
Nov 22 at 14:29
Thank you. Can you think of a way to match all the W characters (except ;;;) in order to replace them?
– user10690376
Nov 22 at 14:21
Thank you. Can you think of a way to match all the W characters (except ;;;) in order to replace them?
– user10690376
Nov 22 at 14:21
Here you get 'what you want', not 'what you don't want', so Theres nothing that should be replaced.
– Poul Bak
Nov 22 at 14:29
Here you get 'what you want', not 'what you don't want', so Theres nothing that should be replaced.
– Poul Bak
Nov 22 at 14:29
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%2f53431660%2fregex-match-not-words-except-token%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
4
"Not-words"? Could you clarify what a "not-word" is?
– connectyourcharger
Nov 22 at 13:06
By not-words i mean any non alphanumeric character. I want to replace all of those except ";;;"
– user10690376
Nov 22 at 13:19