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.
Related
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.
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
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.
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 have recently been asked to take over a large LOB application that uses Entity Framework. Many of the db calls being made use several (>5) Includes, which causes some very heavy query inefficiency. I want to use Visual Studio's search functionality to find some of these include chains. As a quick example, one might look like:
var res = ObjectContext.Items.Include("Details")
.Include("Users").Include("Users.Info");
I'd like to find any instance of more than 1 include, and match regardless of what the include path is.
How can I structure a search to identify these chains? Any help is most appreciated!
VS2012 uses .NET's regex flavor so you could do something like
(?:[.]Include[(]\s*"[^"]*"\s*[)]\s*){2,}
This matches one .Include("something") plus any white space after it and then requires at least two repetitions of this pattern. Note that you'll get problems if your strings contain quotes or you have verbatim strings in there. In that case the "[^"]*" would have to be a bit more elaborate.
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?