Fparsec vs regular expressions [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
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.

Related

Which is better to use: regex.containsMatchIn(String) or String.contains(regex) and why? [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 3 years ago.
Improve this question
If i have a String called "text" and a Regex (called "regex" for ease) i want to check it against, should i use:
regex.containsMatchIn(text)
or should i use:
text.contains(regex)
Both seem to be successful but i am unsure of the best practices concerning this.
Use whichever one makes your code easier to read. There is no difference between them because text.contains(regex) calls the regex.containsMatchIn(text) As per Strings.kt source code:
#kotlin.internal.InlineOnly
public inline operator fun CharSequence.contains(regex: Regex): Boolean = regex.containsMatchIn(this)
The Kotlin documentation says:
contains
Returns true if this char sequence contains the specified other sequence of characters as a substring.
containsMatchIn
Indicates whether the regular expression can find at least one match in the specified input.
It looks like both do pretty much the same thing, so functionally it doesn't matter too much which you use.
However, since you're dealing with regex, I feel like using containsMatchIn is more appropriate since it's part of the regex library and intended for that purpose specifically.
Where contains can be used for more than just regex, e.g. for finding if 'flow' is a substring of 'overflow'. So, it's likely less appropriate to use it for regex, if we're being picky.

Match string inside function [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 want to search for imports in my node modules from visual studio codes regex search, the problem is that i only want to search for imports that are inside functions and not in the whole file. How would i go about doing this?
const a = require('a'); // shouldn't match
function func() {
const b = require('b'); // should match
}
Despite the growing popularity of such features (search in functions, search outside of comments, search in strings, etc), VSCode still doesn't have built-in support for such these.
You'll have to use find with regular expressions for this one, but good luck on building the regex for "a particular pattern inside a function". A good hack that doesn't work all of the time is to detect indentation before your pattern: ^\s+.*YOURPATTERN

How to master regular expression, especially in multiple language [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 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

How to tell if some language's/command's regular expression supports things such as \d \w? [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 9 years ago.
Improve this question
In some languages or commands (eg: javascript) I can use \d, \w
In others I have to use [0-9], [a-zA-Z]
How to tell when I can use \d, \w?
[A side question: can Notepad++ and grep use them?]
Simple answer - RTFM for each language/function what kind of RegExp they support, as there are different dialects, at least (I really don't remember all differences, have to read manual each time for new function):
Perl Compatible
Posix
GNU
And of course not all languages fully supports any kind of standard, so after reading common manual you have to struggle with peculiarities of particular implementation
Look up a reference for the language you're using the regexes in or try them out; we can't give an exhaustive reference here.
Notepad++ does have regex support, but I've found it to be flaky. It's supposed to support the basic character classes, though. Grep, I'm less familiar with. I'd expect it to, but...try and see.

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.