Alphanumeric With Punctuation Regex Expression - regex

Hi I wonder whether someone may be able to help me please.
Firstly, I'm very new to this, so please bear with me.
I've been working through some of the many tutorials to try and come up with a preg match expression which allows:
Any alphanumeric,
Commas,
Full stops and,
Spaces
and I've come up with the following:
(!preg_match('/^[A-Za-z0-9 _.,]{5,35}$/', $nameofcontact))
In addition to this, because the field is optional, I would also like blank fields to pass the validation and it's this aspect that I'm having difficulty with.
I just wondered whether someone could perhaps provide some guidance on how I can allow the field to be blank in conjunction with the above parameters.
Many thanks and kind regards

Blank field : ^$
'Or' in Regex : |
Use this :
^$|^[A-Za-z0-9 _.,]{5,35}$

Related

How to cut url down correctly by regex?

May I ask you some question about regex? It will be cool if you could help me to solve an issue. I have tons of urls and I need to find out all unique which has word promo in url.
For instance, I have a bunch urls like that:
/promo/vygoda-do-20-na-samsung?from=hb
/promo/antikrizisnaya-rasprodazha-skidki-do-50-mark164615151?from=hb
/promo/antikrizisnaya-rasprodazha-skidki-do-50-mark164615151
but I need get like this:
/promo/vygoda-do-20-na-samsung
/promo/antikrizisnaya-rasprodazha-skidki-do-50
/promo/antikrizisnaya-rasprodazha-skidki-do-50
All I could do it is
https://regex101.com/r/Ot8xzV/1
I have just started my journey to regex and don't have strong knowledge, so, please help me to do it. I'll be very grateful
Use
(.*/promo/[^?]+?)(?:-mark\d+|\?).*
Replace with $1 if you can replace. Capturing group may work for you already.
See proof.

Match a url with quety string

I'm pretty new to regex.
I researched a lot, but I can't figure out the problem.
I have this url
https://kompozitor.fr/thenotebar/?s=test.
The query string ?s= is the search parameter on my blog.
I'd like to write a regex expression that matches only
/thenotebar/?s=
and any parameter given to the search engine.
I tried a few things like /thenotebar/\?s=(.*)
,but it didn't work.
Any help is appreciated. Thank you in advance.
As I understand, you need the "thenotebar/?s=" and at least one character in the parameters.
Try to use this regex for it.
/\/thenotebar\/\?s=.(.*)/g
In your regex, you miss the '\' before the '/', probably this is the reason, it not works. You need a dot before (.*). This means you need at least one character as parameter. You need it? Leave this extra dot if you only check the "/thenotebar/?s=" string.

Matching Any Word Regex

I would like to remove hundreds on onmouseover events from my code. the evt all pass different variables and I want to be able to use dreamwaever to find and replace all the strings with nothing.
Here is an example
onmouseover="parent.mv_mapTipOver(evt,'Wilson');"
onmouseover="parent.mv_mapTipOver(evt,'Harris');"
onmouseover="parent.mv_mapTipOver(evt,'Walker');"
I want to run a search that will identify all of these and replace/remove them.
I have tried seemingly infinite permutations of things like:
onmouseover="parent.mv_mapTipOver(evt,'[^']');"
or
onmouseover="parent.mv_mapTipOver(evt,'[^']);"
or
onmouseover="parent.mv_mapTipOver(evt,[^']);"
or
onmouseover="parent.mv_mapTipOver(evt,'[^']+');"
And many more. I cannot find the regular expression that will work.
Any/all help would be appreciated.
Thanks a ton!
"." and "(" have special meaning in regular expressions, so you need to escape them:
onmouseover="parent\.mv_mapTipOver\(evt,'[^']+'\);"
I'm not sure if this is correct dreamweaver regex syntax, but this stuff is standard enough.
Try this one:
onmouseover="parent\.mv_mapTipOver\(evt,'.+?'\);"
And see it in action here.
When using reg expressions you have to be very careful about how you handle white space. For example the following piece of code will not get caught by most of the reg expressions mentioned so far because of the space after the comma and equals sign, despite the fact that it is most likely valid syntax in the language you are using.
onmouseover= "parent.mv_mapTipOver(evt, 'Walker');"
In order to create regexp that ignore white space you must insert /s* everywhere in the regexp that white space might occur.
The following regexp should work even if there is additional white space in your code.
onmouseover\s*=\s*"parent\.mv_mapTipOver\(\s*evt\s*,\s*'[A-Za-z]+'\s*\);"

Regex, how to select all items outside of selection group

I'm a Regex noob and am pretty sure I'm not going about this in the most efficient way - wanted to get some advice.
I have a Regex expression ((\w+\b.*?){100}){1} which selects the first 100 words of my string, the length of which varies.
What I want is to select the entire string except for the first 100 words.
Is there syntax I can add to my current expression to do this, or am I better off trying to directly select the rest of the text instead.
Also, if anyone has any good resources for improving my Regex knowledge, i'd be very appreciative. Thus far I've found http://gskinner.com/RegExr/ to be very helpful.
Thanks in advance!
If you use this, you can refer to everything else as group 3 noted as $3
This one will treat hyphenated words as one word.
(\w+(-\w+|\b).*?){100}(.*)
Regex training Here

Regex not returning 2 groups

I'm having a bit of trouble with my regex and was wondering if anyone could please shed some light on what to do.
Basically, I have this Regex:
\[(link='\d+') (type='\w+')](.*|)\[/link]
For example, when I pass it the string:
[link='8' type='gig']Blur[/link] are playing [link='19' type='venue']Hyde Park[/link]"
It only returns a single match from the opening [link] tag to the last [/link] tag.
I'm just wondering if anyone could please help me with what to put in my (.*|) section to only select one [link][/link] section at a time.
Thanks!
You need to make the wildcard selection ungreedy with the "?" operator. I make it:
/\[(link='\d+')\s+(type='\w+')\](.*?)\[\/link\]/
of course this all falls down for any kind of nesting, in which case the language is no longer regular and regexs aren't suitable - find a parser
Regular Expressions Info a is a fantastic site. This page gives an example of dealing with html tags. There's also an Eclipse plugin that lets you develop expressions and see the matching in realtime.
You need to make the .* in the middle of your regex non-greedy. Look up the syntax and/or flag for non-greedy mode in your flavor of regular expressions.