Checking url string in Regular Expression - regex

Admit that I suck in writing regular expression. Please help me to solve how to write regular expression for success-apply founded in URL just like http://www.example.com/success-apply/

Assuming that the pattern success-apply changes:
example\.com\/([^\/]+)
# capture everything that is not a forward slash one or unlimited times
Here is this regex example with PCRE (PHP).
If you however only want to know if the string is there at all, regular expressions seem a bit of an overkill. Consider the following PHP code:
if (strpos($url, 'success-apply') !== FALSE) {
// do sth useful
}

Is this what you are looking for?
(success-apply)

Related

Regular Expression Pattern which should not allow ,;:|

I need the regular expression pattern which should not allow to put any of following characters into input in HTML
,;:|
You may get some idea from this.
[^,;:|]+
DEMO::: https://rubular.com/r/dKQzC1HrnMG88X

(Notepad++) Replace with regular expression: FixedText(xxx[yyy],whatever) to FixedText(yyy, xxx[yyy],whatever)

Sorry for not knowing the basics of regular expressions and asking this, but I couldn't get to it myself.
I need to replace all expressions PlayerTextDrawSetString(SSbank[playerid],strBank)
with PlayerTextDrawSetString(playerid,SSbank[playerid],strBank)
,
PlayerTextDrawSetString(SWant[someid],strWant)
with PlayerTextDrawSetString(someid,SWant[someid],strWant)
etc.
I can find such expressions with PlayerTextDrawSetString+\(+.+\[+.+\], but I can't replace them with that (\1, \2, \3 etc. return empty symbol).
I tried different search strings, but in all cases I get nothing on \1, \2, etc.
Could you please write the correct regex for me?
Thank you in advance for the help.
Try these expressions:
Search:
(PlayerTextDrawSetString\()(\w+\[)(\w+)
Replace:
\1\3,\2\3
The first two examples work.
Search Pattern 1:
SSbank\[([^\]]+)\]
Replacement Pattern 1:
\1,SSbank[\1]
Search Pattern 2:
SWant\[([^\]]+)\]
Replacement Pattern 2:
\1,SWant[\1]
To go all out if you have a lot of these similar patterns you can do this:
Total Replacement Search:
\((\w+)\[([^\]]+)\]
Total Replacement String (yes the first slash is needed... a bug maybe?):
\(\2,\1[\2]
Look behind is apparently broken.
I tried to give Notepad++ a shot with the positive look behind but the replacement fails even though the match happens. Here's the pattern:
(?<=\()(\w+)\[([^\]]+)\]
My attempted replacement (doesn't replace anything in Notepad++ v6.3.2):
\2,\1[\2]

QRegExp Pattern For URLs

I am trying to match google urls from some text that is stored in a variable, using the pattern below.
The urls use double quotes
QRegExp regExp;
regExp.setPattern("http://www.google.com/(.*)");
I manage to match the url but it unwontedly matches all of the text that is contained after it. I have tried using similar variants like the ones below, but they don't seem to work.
regExp.setPattern("http://www.google.com/(.*)\"is");
regExp.setPattern("http://www.google.com/^(.*)$\"");
Any help to get a regular expression that matches just the url alone.
Thanks in advance
Is there a reason you need/want to use a QRegExp?
You could use a QUrl most likely.
Even though it is impossible for us to know what is around the urls in your text (quotes ? parenthesis ? white spaces ?), we can create a better regular expression by trying to do a negative match of characters that cannot be part of the url:
QRegExp regExp;
regExp.setPattern("http://www.google.com/([^()\"' ]*)");
Then you just need to add more possible characters to this negative character class.

Regular Expression Pattern To Accept An Apostrophe

I am using Regular Expression in Jquery to validate names.I am having this issue that i need a pattern which will allow an apostrophe in the name.That means it can have alphabets and a single apostrophe.
Valid: D'souza,Danny
Invalid: D''souza
Can anybody help me out with this.Currently I am using this pattern
var rxPattern = /^([a-zA-Z]+)$/;
Thanks
You probably need something like that:
[a-zA-Z]+('[a-zA-Z])?[a-zA-Z]*

Regular Expression - Want two matches get only one

I'm working wih a regular expression and have some lines in javascript. My expression should deliver two matches but recognizes only one and I don't know whats the problem.
The Lines in javascript look like this:
if(mode==1) var adresse = "?APPNAME=CampusNet&PRGNAME=ACTION&ARGUMENTS=-A7uh6sBXerQwOCd8VxEMp6x0STE.YaNZDsBnBOto8YWsmwbh7FmWgYGPUHysiL9u0.jUsPVdYQAlvwCsiktBzUaCohVBnkyistIjCR77awL5xoM3WTHYox0AQs65SoHAhMXDJVr7="; else var adresse = "?APPNAME=CampusNet&PRGNAME=ACTION&ARGUMENTS=-AHMqmg-jXIDdylCjFLuixe..udPC2hjn6Kiioq7O41HsnnaP6ylFkQLhaUkaWKINEj4l2JqL2eBSzOpmG.b5Av2AvvUxEinUhMBTt5awdgAL4SkBEgYXGejTGUxcgPE-MfiQjefc=";
My expression looks like this:
(?<Popup>(popUp\(')|(adresse...")).*\?((?<Parameters>APPNAME=CampusNet[^>"']*["']))
I want to have two matches with APPNAME...... as Parameters.
[UPDATE] Like Tim Pietzcker wrote i used the greedy version and should have used the lazy version. while he wrote that i solved it myself by using .? instead of . in the middle so the expression looks like this:
(?<Popup>(popUp\(')|(adresse...")).*?\\?((?<Parameters>APPNAME=CampusNet[^>"']*["']))
That worked. Thanks to Tim Pietzcker
Your regex matches too much - from the very first adresse until the very last " because it uses a greedy quantifier .*.
If you make that quantifier lazy, i. e.
(?<Popup>(popUp\(')|(adresse...")).*?\?((?<Parameters>APPNAME=CampusNet[^>"']*["']))
you get two matches.
Alternatively, if your data allows this, use a different quantifier that only matches non-space characters. This will match faster (but will fail of course if the text you're trying to match could possibly contain spaces):
(?<Popup>(popUp\(')|(adresse..."))\S*\?((?<Parameters>APPNAME=CampusNet[^>"']*["']))
Usually you must apply the regex with the "global" flag to find all matches. I can't really say more until I see the complete code sample you are working with.