Recognize pattern of characters [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 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.

Related

How should I read this regex pattern of bash? [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 want to ask about read the regex pattern. I have a regex pattern
"/^[ \t]*\/\*<O$firstline>\*\//,/^[ \t]*\/\*<\/O$firstline>\*\//s/\/\///g" $Path/DebugVersion.c
How should I read this pattern? I need an explanation about this regex. If anyone can explain this to me you can reply this questions. I'm thankful if you answer this question.
Regard,
Gustina M.S
This actually looks like a sed expression, and it consists of two regular expressions expressing a range, and another regular expression in a search/replace command. The basic structure of the command is:
/START_EXPRESSION/,/END_EXPRESSION/ COMMAND
Where START_EXPRESSION and END_EXPRESSION are both regular expressions, and COMMAND_EXPRESSION is a sed command that will execute for every line in between those two expressions (inclusive).
Just to make it clear, the range expression is:
/^[ \t]*\/\*<O$firstline>\*\//,/^[ \t]*\/\*<\/O$firstline>\*\//
Or, splitting that up a little more:
START_EXPRESSION: /^[ \t]*/**//
END_EXPRESSION: /^[ \t]*/*</O$firstline>*//
And COMMAND is s/\/\///g.
The link that a commenter provided to https://regex101.com/ should help you understand the individual patterns, and the sed man page will also be a useful resource.

understanding the nitty and gritty of regular expressions [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
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,}

Is it OK to mix string parsing while learning reg ex? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm performing some regular expression exercises in Python 2.7.3, on Windows 7. Some of these exercises have me looking for similar patterns on the same line. For example, I want to use regex to capture name1 and name2...
<XML tag><more tags>[name1]</XML tag><XML2 tag>[name2]<XML2 tag></more tags>
Would it be "cheating" or "missing the point" if I used any string parsing to capture name2? I feel like using regex the correct way alone should be able to capture both of those names, but string parsing is what I've always been familiar with.
An analogy would be like someone studying recursion in C++, but using a While loop. Recursion should NOT have any While loops (although of course it may be part of some other grand design).
Good question! Many beginners come into it believing they should be able do everything with one regex match. After all, people are always saying how powerful regexes are, and what you're trying to do is so simple...
But no, the regex is responsible for finding the next match, that's all. Retrieving the substring that it matched, or finding multiple matches, or performing substitutions, that's all external to the act of matching the regex. That's why languages provide methods like Python's findall() and sub(); to do the kind of "string parsing" operations you're talking about, so you don't have to.
It occurred to me a while back that the process of mastering regexes is one of learning everything you can't do with them, and why not. Understanding which parts of the regex matching operation are performed by the regex engine, and which parts are the responsibility of the enclosing language or tool, is a good start.

Converting Regular Expressions For Use With VBA [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 9 years ago.
Improve this question
Forgive me if this seems basic, but I'm new to regular expressions, and I can't seem to find general information that isn't example driven.
Basically, I'd like to know what to keep in mind when converting regular expressions found around the internet for use with vba. Is it as simple as "oh, just change the non-greedy operator to this ...", or is it involved on a level that I really need to find VBA specific expressions, or get better at writing my own.
My specific example involves converting this phone number pattern
^((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}$
But i'm really more interested in either a general approach, or an affirmation of its futility. Thanks!
Following up on Cor_Blimey and funkwurm's comments, I have used VBScript 5.5 regexes in Office 2003 and Office 2007 VBA with good success. Details here. For anything more complicated than () and [] groups, I have found writing from scratch more effective than trying to modify an existing expression.

Can a regex be used as input method? [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 9 years ago.
Improve this question
I saw somewhere that a regex can be used as an input method, is this possible? How?
I really don't know anything else about that, I supposed that there's a way to procude Strings from a regex and feed an object with that String, again, this is only what I pictured and I don't know if it's even possible.
EDIT
I know I didn't explain myself, I was in a hurry, sorry for that. Well, long story short. Last week I saw an article about regex, and in one paragraph said "regex could be used as input", thats all it said about that, I couldn't find the article again so I think I could ask here.
Thanks for the votes down. Next time I'll make sure to explain correctly my doubts and to not piss someone off...
A regular expression is not an "input method". A regular expression can be used to constrain input though.
A regex can be input, if your users are the sort that live, eat, and breathe regexps (I can't imagine who would do so...), but even so, that regexp won't become the method.
Since a regex is just a string, it is techniclaly possible to use it as either:
a user input to a program (not often, but I hav seen some applications accept them, usually as a form of "advanced" search filtering)
an input parameter to a method call which accepts a string.
Perhaps one of these is the answer you are looking for?