How to master regular expression, especially in multiple language [closed] - regex

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 always want to master regular expression, although it isn't encouraged to use in many scenarios. But regex is a neat tool for occasional use. Everytime I need regex i spent lot time on cheat sheet or stackexchange. I try to read few book but most of them don't have enough example. And the regex seems to be slightly different in different languages. I can't write it in java after switching from writing it in python. I'm wondering is there any good way to master the regex? Any recommendation will be great.

I found this book "Mastering Regular Expressions, 3rd Edition by Jeffrey E.F. Friedl " really helpful in understanding regular expression. You can get your copy here
In initial chapters, book details the syntax to write regular expression.
Last four chapters are really helpful in using regular expression in different languages like a> Perl b> Java c> .NET d> PHP
This is one of the useful tool to test the regular expression online. You can find it here

Related

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.

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.

Fparsec vs regular expressions [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
What is the advantage of using a library like FParsec for parsing text over using plain regular expressions from a .NET language?
FParsec can recognise (at least) context-free grammars whereas regular expressions can only recognise regular languages, at least without using somewhat hacky extensions.
One example of something you can't do with a regular language is bracket matching, i.e. tracking the number of opening and closing brackets and make sure that they match up.
Of course you can emulate this with regular expressions by using them repeatedly, but embedding the behaviour into a single parser is significantly cleaner.

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.

Boost regular expressions [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
Does anyone know of any good tutorials on regular expressions using boost? I have been searching for a decent one, but it seems most are for people who know a little about regular expressions
You may want to look at sections 23.6, 23.7, 23.8, and 23.9 (pp. 830-849) of Bjarne's Stroustrup's new book: Programming: Principles and Practice using C++
Just like the rest of the book, these sections are very pedagogical and assume essentially zero background on regular expressions.
I always find the O'Reilly articles to be pretty helpful for many things. You could give this a try. If the problem is that you're not too familiar with regular expressions, I'd read this site for a primer on Regexes. Pay close attention to the Perl section, as many systems, including Boost, commonly support Perl-compatible Regexes.
Once you understand the basics, go for either the Boost docs or the aforementioned O'Reilly guide.