In order to keep a regular expression more brief, is there a shorthand way to refer to a character class that occurs earlier in the same regular expression?
Example
Is there a way to shorten the following:
[acegikmoqstz##&].*[acegikmoqstz##&].*[acegikmoqstz##&]
Keep in mind that regex features are dependant on the language being used.
With Java, you can do this:
[acegikmoqstz##&](?:.*[acegikmoqstz##&]){2}
But that's all, with java you can't refer to named subpattern.
With PHP you can do that:
(?(DEFINE)(?<a>[acegikmoqstz##&]))\g<a>(?:.*\g<a>){2}
Related
In boost spirit there are parantheses which can be used to indicate that a part of grammar is going to be repeated
A>>(B>>C)*
I want to use this concept to write a generic scenario controller but I have no idea how they implemented that the parantheses are implicitly creating some object around B and C
Well, it seems you're asking about the attributes of rules. Spirit can propagate the parsed content automatically to data types. Each parser, also *(...), defines rules how those data types should look like. You'll find it as "attribute propagation" in the documantation.
Here are two interesting links for this subject:
http://boost-spirit.com/home/articles/attribute_handling/attribute-propagation-and-attribute-compatibility/
http://www.boost.org/doc/libs/1_55_0/libs/spirit/doc/html/spirit/abstracts/attributes.html
In a SQLite3 CREATE TABLE statement, can I use a regular expression to enforce a particular constraint? Specifically, I am trying to require that an inputted URL is valid. I know there are other ways of doing this besides using regular expressions, but because of the structure of my project, this is the method I need.
You can use regular expressions only after you've installed a user-defined REGEXP function; SQLite doesn't have one by default.
But if you have it, you can use REGEXP also in a CHECK constraint.
I want to recognize all of my servers over my office network. They have a particular naming pattern which only I use. I've defined it in a simpleType.
Now I was told I have to filter my servers from a list of full DNS names (like www.bla.moo.oneofmyservers.foo.loo). My naming strategy has a length limit. I would have simply put it inside a *mystrategy* if not for that.
Is there a way to reference my type from within a pattern definition?
It didn't work when I wrote *mytype*.
Assuming that what you're asking is something like this:
I have a pattern and I've used it as a constraining facet in a simple type; now, I want to make another type, and for maintenance purposes, I wish to somehow reference that pattern, so that I don't have to maintain it in two different places...
The answer is no, you can't. Constraining facets in XSD are not referenceable entities; nor types are referenceable within constraining facets.
What are the regex expressions for reliably finding C++ methods and classes?
There are no regular expressions to reliably find C++ methods and classes. You need a real parser.
Regular expressions really are not suited to parsing languages like C++. Features of the language like templates require additional knowledge to parse properly.
Consider the following
template<class T> T SomeTemplate();
typedef int SomeType;
if(SomeTemplate<SomeType>())
{
}
How do you distinguish between a comparison and calling a template function?
I have this much
Code snippet:
int *filePointer;
float *valPtr;
*valPtr = 5.6;
filePointer = ∑
I would like to replace all pointer variables as follows, for example
*filePointer have to be converted to *filePointer_p.
filePointer have to be converted to filePointer.
valPtr have to be converted to valPtr_p
How can I do it using Regular Expression.
It sounds to me like you might be asking how to use regular expressions as a generic tool to rename all pointer variables in source code. I am assuming that the provided snippet is just an example.
If my understanding of your goal is correct, it is not possible to do that with regular expressions. A regular expression would not be able to determine reliably from the context if a variable is a pointer. Consider, for example, a=b;. a and b could be pointers or they could be most anything else. A regular expression by itself would not be able to determine that.
The first is simply:
s/\*filePointer/*filePointer_p/g
Not sure what you're second is on about? But if you're basically out to rename filePointer, then you should be able to simply do:
s/filePointer/filePointer_p/g
on the assumption that there aren't any other variables or context that contain the text filePointer in a different context.
For 1, try s/\*filePointer/*filePointer_p/g.