understanding the nitty and gritty of regular expressions [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
need some talking through and explaining regular expressions as it seems obvious but then I will write one and it wont validate and I cant understand why.
I am using http://regexpal.com/ to test my expressions and am trying (ultimately) to validate a password. but to start I just want to simply match a string of words of 8 or more characters.
according to this http://www.cheatography.com/davechild/cheat-sheets/regular-expressions/ I should have most of what I need. This webpage tells me that \w matches a word character and then a + does 1 or more. this matches every individual expression I am testing (great). now I want to match only those that have 8 or more characters. so 'messi' should not validate but 'lollollol' should. so I then wrote this (\w+{8,}) expression but nothing was highlighted, aka nothing validated. I used () brackets to try and group everything together but it made no difference. can anyone see where my thinking is going wrong?

You must need to remove the following + from your regex. Since + does the job of repeating the previous token one or more times, likewise {8,} would repeat the previous token that is \w exactly 8 or more times. So you don't need to include the + in this (\w+{8,}) pattern.
(\w{8,})
Use capturing groups if necessary or otherwise go for matching.
\w{8,}

Related

Regex that does not repeat the same character 2 times in a row [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 2 years ago.
Improve this question
I need to make a regex to validate an amount in which it only accepts numbers, points (.) Optional, 1 comma (,) optional and that after the comma I have at least 2 more numbers, the farthest I've come is this
^(([0-9]{0,})+([.]?))+([,]{0,1}?)([0-9]{1,}?)+$
This works fairly well, the problem is that it allows me to put the period (.) Followed more than once for example (100 ... 000), this accepts it, but I need it to only accept one period (.) At a time, how do i fix it?
I need the regex to validate as follows
100 VALID
100.000,00 VALID
100. INVALID
100..00 INVALID
100, INVALID
100..000,00 INVALID
To prevent the same character (in this case a dot) appearing consecutively, use a negative look ahead anchored to start of input:
^(?!.*[.][.])<rest of regex>
In your case:
^(?!.*[.][.])(([0-9]{0,})+([.]?))+([,]{0,1}?)([0-9]{1,}?)+$
See live demo with test cases from question.
I'm not clear on what you actually want to match, but I don't need to understand that to answer your question, which was how to prevent the same character appearing consecutively.

Matching up to special character [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 need to capture something until a , (comma).
Example payload1: AgentBrand: Internet Explorer,
Example Payload2: AgentBrand: OutlookPlug-in,
From the above payload I need to capture whatever coming after AgentBrand:
until the command (,).
I have Tried AgentBrand:\s+(\w+\s+\w+) .But this will be become a lengthy regex.
Thanks
The current regex that you are using - AgentBrand:\s+(\w+\s+\w+) will only catch cases where you have at least two words separated by a space and even in those cases it will only pick up the first two words (when there may be more).
A better regex to use would be - AgentBrand:\s*(.*?),
what this does is
AgentBrand: - looks for the string 'AgentBrand:'
\s* - matches zero or more space characters
(.*?) - captures any characters non-greedily [takes minimum matches to satisfy result]
, - looks for a comma at the end
Also as a note, the length of a regex is not always a good reason to avoid using one. The regex in your example is not that long and is quite simple and could be freely if it met all your requirements. Looking at the complexity of a regex is a better choice

Recognize pattern of characters [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 am student in the college and I need some help with recognition pattern of characters: what it will match ? or maybe somebody can explain how does it work ?
" (k[abc]*p)+ "
Thank you for any help.
This is a bit of a vague question as you're basically asking how regular expression work.
First of all I would recommend 'Mastering Regular Expressions' which is a pretty great O'Reily book on regex.
Also, for a regex playground, I really like to use Rubular (http://www.rubular.com/) as a playground, although this is meant for ruby, it can give you a good understanding into general regex expression and comes with a nice quick reference guide.
Taking some time to figure this out yourself will be very helpful, regular expressions are not going away.
In this case, your expression is evaluating everything inside the () as one chunk. So it's looking for a k, then at least one (+) of either abc ([abc]) followed by a p, at least one time (+).
So things like kap, kabcp will match.

My regex pattern is failed [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 need some help. My data;
{foreach $page_list as $page}
<li>{$page->name}</li>
{/foreach}
And my pattern;
~\{foreach\s\$(.+)\sas\s\$([^\{]+)\}([^\{]+)\{\/foreach\}~
But it's not working. What is wrong ?
The pattern with which you are trying to exclude the line between the two {foreach...} regions explicitly does not match '{' characters, but two are present in the string. Since that middle area's match is broken somewhere that doesn't get followed by a {/foreach}, the entire pattern fails to match.
That entire portion of the pattern should possibly be .* instead. Rely on backtracking to catch the closing {/foreach}. Of course, this will erroneously match an entire list as one thing, but regular expressions in general can't match quotes (without backreferences, which are technically non-regular and hurt performance), so you might need another parsing strategy entirely.

Regex - Without Special Characters [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 1 year ago.
Improve this question
I'm using regex to validate username
^[a-zA-Z]+\.[a-zA-Z]{4,10}^'
Unfortunately it doesn't affect if the the value contains special characters such as !##$%^&*)(':;
I would glad to get some help for Regex that contains:
Alphanumeric only (a-zA-Z0-9)
Length between 4 - 10 characters.
The conditions you specified do not conform to the regexp you posted.
the regexp you posted ^[a-zA-Z]+\.[a-zA-Z]{4,10}^ is erroneous I guess, because of the ^ in the end, it will never be matched to any expression, if you want to match with the ^ at the end of the expression, you need to escape it like this \^. but ^ alone means "here is the start of the expression", while $ means "here is the end of the expression".
Even though, it denotes:
It starts with alpha (at least 1).
there must be a '.' period character.
Now there must be at least 4 alphas.
The regexp you need is really is:
^[a-zA-Z0-9]{4,10}$
This says:
It starts with alphanumeric.
There can be minimum of 4 and maximum of 10 of alphanumeric.
End of expression.
Try this:
^[a-zA-Z0-9]{4,10}$