Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to program a Search. The main problem is to search for quoted Text and using + and minus for the Search.
I hoped there is a regex expression for searching for e.g.
var test = '"search test" searchword2 -searchword3';
Should result in
[0] = 'search test';
[1] = 'searchdword2';
[2] = '-searchword3';
Thank You
Edit:
Sry, but I want to have the first result without quotation marks. My Mistake.
It seems you want to split the string on whitespace, except if that whitespace is enclosed in quotes. Right?
In that case (and assuming you don't have to deal with escaped quotes within quoted strings), try
"[^"]*"|\S+
See it on regex101.
If there could be escaped quotes (\") in your string, use
"(?:\\.|[^"])*"|\S+
See it on regex101.
I think if you just want a regex that will split the terms out you could use
("(\w|\s)+")|([-+]?(\w)+)
http://rubular.com/r/aOKs3nF7Fk
Although your question lacks clarity
Hmmm you may want to try:
/"[\w ]+"| (?:-|\+)?\w+ ?/g
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Hello there can i have an hint about how should i write the regex code to search for the commas (,) in those values between the |'...'| pattern? i need to find the commas and replace with dots(.) , if there's a comma in there of course.
|'2,3'|;|'5,6'|;|'2,1'|;|'3'|;|'6,5'|;|'9'|;|'7'|;|'4,4'|;|'4'|;|'1,1'|
expected result:
|'2.3'|;|'5.6'|;|'2.1'|;|'3'|;|'6.5'|;|'9'|;|'7'|;|'4.4'|;|'4'|;|'1,1'|
the pattern can be also what i will write below depending on some input parameters that i am going to receive in my method:
|'2,3'|,|'5,6'|,|'2,1'|,|'3'|,|'6,5'|,|'9'|,|'7'|,|'4,4'|,|'4'|,|'1,1'|
expected result:
|'2.3'|,|'5.6'|,|'2.1'|,|'3'|,|'6.5'|,|'9'|,|'7'|,|'4.4'|,|'4'|,|'1.1'|
this why i need a pattern for this because i don't know if i will receive the string with (;) or (,) separating the values
thanks so much
Regex Pattern
Here is the pattern that you can use to search for the commas , between two numbers
(?<=[0-9]),(?=[0-9])
Regex Demo
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I tried to find all comments beginning with // that don't have a space after the slashes.
I want to select only the slashes. No whitespace or text before that, no whitespace or text after that.
So far I've reached to [\s].(\/\/(?! )) but it catches the space before the slashes as well.
Basically I wanna make sure my line comments have a space after the slashes.
I'm trying to do this either in JavaScript or in any text editor.
Since javascript doesn't have the lookbehind feature, you can't.
The workaround (for instance, in a replacement context) is to use a capture group for the character before the two slashes and to start the replacement string with a reference to this group ('$1replacement'):
([^/\s]|^)//(?! )
You can use the following regex:
.*(\/\/(?= )) demo
The idea is to use positive lookahead and capture the // iff it is followed by a space.
EDIT: Just noticed that your question is contradictory. So if you want to capture if the // is not followed by a space, use this: .*(\/\/(?=\S)). Otherwise use the one above.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have this regex string:
("prodcssstart.*prodcssend","xx")
and my file like this:
prodcssstart
<!--<link href="content/bundles/css.min.css" rel="stylesheet" />-->
prodcssend
But when I run it then it fails to find the expression.
Can someone suggest what I might be doing wrong, I've simplified it so much but I am thinking maybe there is a problem with the .* that I use to match everything. Any help would be much appreciated.
First of all, you can't parse HTML with regex.
But in your case the problem is most likely caused by newlines, because by default the dot doesn't match the newline. You need to pass the proper switch to disable this (e.g. re.DOTALL in Python and s in Perl).
You could come up with a tempered greedy token solution:
prodcssstart
(?:(?!prodcssend).)*
prodcssend
Breakdown:
look for prodcssstart
match any character as long as it is not followed by prodcssend
match prodcssend
See a demo on regex101.com (mind the different modifiers!).
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to process search results using regex?
E.g., I have a file with many strings like AB.
I want to get: 'AB'.
The letters always differ.
So I would search for the regex pattern ^\w+\n and want to use the search result, let me use '$#' to depict it, to get '$#'.
Regex:
(?<=:)([^,]+)
REplacement string:
'$1'
DEMO
Just to clarify: You want 71:A,72:BC,73:ABD to become 71:'A',72:'BC',73:'ABD' right?
Do a find/replace in whatever language or program you are using:
Find: (\w+)
Replace: '$1'
This finds ANY multi-letter string in your file and puts ' around it. if you only want to do the ones with [number:string] you will need to use a look-ahead like (?=\d+:) in front of the (\w+). So the whole Find would then look like (?=\d+:)(\w+), similar to what Avinash Raj has posted.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I hate to ask specific question, but i need the regex code for matching strings like :
{block any_single_word_here}
Anything Here
{/block}
Your original query is very close, albeit a little verbose. It can be shortened to:
/{block (.+?)}(.+?){\/block}/
(The ? modifier stops the + from being "greedy", so you don't have to explicitly stop the match at the next } or {.)
Next you have to consider that . won't match newlines by default. You can change this with the /s flag:
/{block (.+?)}(.+?){\/block}/s
Here's a demo.
And here's the documentation from man perlre:
s
Treat string as single line. That is, change "." to match any character whatsoever, even a newline, which normally it would not match.
In javascript (added escape to end of lines in original string) I added a \s* (zero or more spaces) to your regex and it outputs a match for any_single_word_here and Anything Here fine...
alert( "{block any_single_word_here}\
Anything Here\
{/block}".match(/\{block ([^\}]+)\}\s*([^\{]+)?\{\/block}/) )
For simpler regex, remove the unneccessary escaping, and just capture with . rather than complex [^\}]
/{block (.+)}\s*(.+){\/block}/
Does this do the job?
/\{block \w+\}\r?\n.*?\r?\n\{\/block\}/i