very simple regex code for a specific string [closed] - regex

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

Related

Is there a Notepad++ RegEx to remove everything but digits and spaces? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Is there a RegEx to remove everything but digits and spaces in Notepad++?
I know there is one that removes only digits but i dont need that.
PS: I do not want the lines to be removed
Example:
11234123 alex-james
1412412 mmafsmasdas
After regex:
11234123
1412412
As the pattern use [^\d ]+. Almost what Poul Bak proposed, but change * into +, i.e. the sequence of chars to match should be non-empty.
There is no point in searching for an empty string and replace it with another empty string.
correction:
try this:
([^0-9| ]+)
this will surely work!!!
open the file in notepad++ press CTRL+H check the box with search mode regular expression and put in the above regex and click replace all

Regex for remove everything after "_" in all anchor Tag [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I want any regex to remove everything after underscore in all anchor Tag e.g
input: Text
Output Text
Although you should avoid parsing HTML with regex, but since this is a case of anchor tag which won't be nested, hence you can do a quick work using regex. Use this regex to match the data in group1 and group2,
(<a\s+[^>]*?href=["'][^']*?)_.*?(["'])
and replace it with \1\2 (or $1$2 as per the language)
Check the demo
You haven't mentioned how should the data be replaced in case there are multiple underscores in the href attribute, so for now I have done it in a way where it replaces everything from first occurrence of underscore but you can easily do it for last occurrence of underscore by making the regex as greedy.

Using regular expressions to locate line comments without spaces [closed]

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.

Very simple regex not finding my search text [closed]

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!).

Regex-Expression for a logical Searchstring [closed]

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