Regular expression which will support forward slashes and fullstops - c++

I need to find a regular expression which will support the following format
.[A-Z-a-z]/-
Would ^(\.[A-Za-z]\/-?)+$ work fine ?
i.e
.V/-.E/-
BUT THE - IS OPTIONAL
I trield ^(\.[A-Za-z]\/-)$
but i cannot seem to find a regular expression to support the - at the end
Could someone show me where i am going wrong please.
Thanks

If you want the regex to match the string ".V/-.E/-", you could use this:
^(\.[A-Za-z]\/\-?)+$

This should be as simple as adding a ? after the -. The whole regex would be ^\.[A-Za-z]\/-?$ (don't need the parens unless you are using backreferences)

Related

why with look behind regex, the replacement is not working well in Notepad++?

In Notepad++, for example if the search regex is
(?<latex>\$[^\$]*\$)(?=[\x{4e00}-\x{9fa5}])
and the replace is
~\g{latex}~
then the replacement is working properly.
But if the search regex contains look behind expression like
(?<=[\x{4e00}-\x{9fa5}])(?<latex>\$[^\$]*\$)(?=[\x{4e00}-\x{9fa5}])
then replace
~\g{latex}~
doesn't work in Notepad++, why???
Actually, I found out that your named backreference is the actual problem. As per the documentation, you need to use the syntax $+{name} for a named capture reference in the replace. So that one should work:
(?<=[\x{4e00}-\x{9fa5}])(?<latex>\$[^\$]*\$)(?=[\x{4e00}-\x{9fa5}])
And replace with:
~$+{latex}~
So the first regex you had should not be working properly, but replacing with literal ~g<latex>~. Even so, I can't really be sure here since I'm using an older version of N++ and the docs could be out of date.
Though I think that the simplest would be that you don't use the capture group. The below should work fine:
(?<=[\x{4e00}-\x{9fa5}])\$[^$]*\$(?=[\x{4e00}-\x{9fa5}])
And replace with ~$0~.

Perl Extended Regular Expressions - match with multiple question marks inside

I have got a weird thing to solve in perl using regular expressions.
Consider the strings -
abcdef000000123
blaDeF002500456
wefdEF120045423
All of these strings are matching with the below regular expression when I tried in C with pcre library support :
???[dD][eE][fF][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
But I'm unable to achieve the same in perl code. I'm getting some weird errors.
Please help with the piece of perl code with which these two things match.
Thanks in advance...
? is called quantifier that makes preceding pattern or group an optional match. Independently ? doesn't make any sense in regex and you are getting an error like: Quantifier follows nothing in regex.
Following regex should work for you in perl:
...[dD][eE][fF][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
OR even more concise regex:
.{3}[dD][eE][fF][0-9]{9}
Each dot means match any character.
PS: You probably are getting confused by shell's glob vs regex.
That looks more like a file system regex than a PCRE. In Perl, the ? is a quantifier, not a wild card. You may want to replace them with . to get the same results in anything Perl compatible.
I might use ...[dD][eE][fF][0-9]{9} or even replace the [0-9] with \d.
qr/[A-z]{3}def[0-9]{9}/i
should be the Perl Regex object used to validate the mentioned strings.
Regards

Regular Expression, match ${ANY_TEXT}

Can you please help me with reg ex. I cant make it :( I hate regex.
I need to match this string ${ANY_TEXT} .Exactly one "${" and exactly one closing tag "}".
Thanks a lot. :)
\$\{[^}]+\} will match it. It will match ${ABC} from ${ABC}}} as well. If you want to match complete lines, simply anchor the regular expression using ^\$\{[^}]+\}$.
A good site to learn regular expressions is http://www.regular-expressions.info/.
I suppose this covers all the texts.
/^\$\{[a-zA-Z]\}$/

is it the right reqular expression

i have following regular expression but it's not working properly it takes only three values after # sign but i want it to be any number length
"/^[a-zA-Z0-9_\.\-]+\#([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/"
this#thi This is validated
this#this It is not validating this expression
Can you please tell me what's the problem with the expression...
Thanks
If you want your regex to match "any number length" then why are you using {2,4}?
I think a better example of the strings you're trying to match might give others a better idea of what you want, because based on your regex it is a bit confusing what you're looking for.
Try this:
^[a-zA-Z0-9_.-]+#([a-zA-Z0-9-]+\.)+[a-zA-Z0-9]{2,4}$
The main problem is that you didn't escape the dot: \.. In regular expression the dot matches everything (mostly), making your regex quite liberal.

RegExp: want to find all links that do not end in ".html"

I'm a relative novice to regular expressions (although I've used them many times successfully).
I want to find all links in a document that do not end in ".html"
The regular expression I came up with is:
href=\"([^"]*)(?<!html)\"
In Notepad++, my editor, href=\"([^"]*)\" finds all the links (both those that end in "html" and those that do not).
Why doesn't negative lookbehind work?
I've also tried lookahead:
href=\"[^"]*(?!html\")
but that didn't work either.
Can anybody help?
Cheers, grovel
That regular expression would work fine, if you were using PERL or PCRE (e.g. preg_match in PHP). However, lookahead and lookbehind assertions are not supported by most, especially the more simple, regular expression engines, like one that is used by the Notepad++. Only the most basic syntax such as quantifiers, subpatterns and characters classes are supported by almost all regular expression engines.
You can find the documentation for the notepad++ regular expression engine at: http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Regular_Expressions
Edit: Notepad++ using SciTE regular expression engine and it does not support look around expressions.
For more info take a look here http://www.scintilla.org/SciTERegEx.html
Original Answer
^.*(?<!\.html)$
You can make a regexp that does it, but it would probably be too complex:
href=\"((([^"]*)([^h"][^"][^"][^"]|[^t"][^"][^"]|[^m"][^"]|[^l]))|([^"]|)([^"]|)([^"]|))\"
Thank you all very much.
In the end the regular expression did indeed not work.
I simply used a workaround, and replaced all links with themselves+".html", then replaced all occurences of ".html.html" with ".html".
So I replaced href=\"([^"]*)\" with href="\1.html" and then .html.html with .html
Thanks anyway, grovel
Note that Notepad++ (now?) supports assertions like this. (I have Notepad++ 6.3, dated Feb 3 2012.)
I believe the Regular Expressions documentation implies that both replace-variants use the same PCRE-dialect:
standard: Search | Replace (default shortcut Ctrl H)
plugin: TextFX | TextFX Quick | Find/Replace (default shortcut Ctrl R)