how can i use ^ expression properly in Flex? - flex-lexer

I am trying to use the ^ expression to get any string that is not certain characters, but I can't seem to figure it out.
this is what I am trying to do
STRING [^<>"<!!""!!>"\n]+
but when I input one ! in the text it doesn't recognize it as string, is there a way to make this work?
just to be clear I want that any string would be a STRING with the exception of < > <!! !!> \n the problem is !!> I think.
thanks for the help!

Related

Regular Expression Assistance (RegEx)

I'm trying to create a regular expression string that will capture the data between the opening and closing [] brackets and include the brackets from the following data:
data: [{"LOTS OF DATA}],
datatype: "local",
So far I'm using a regEx string "data:(.*)" and this is returning:
[{"LOTS OF DATA}],
This is almost correct but includes the ',' and the reason this is working is because theres a newline or carriage return before 'datatype:' So I have two questions:
How do I capture all characters including the newline & carriage return?
How do I match the ', datatype:' string. The issue with this is that I cannot guarantee the character type and number of characters between the ',' and 'datatype:' string, I need a wild card? The regEx string would look something like "data:(.*),???datatype:" where ??? is the wildcard?
Thanks for your help, this will be used within an iOS application.
data:\s*\[([^\[\]]*)\]\s*,\s*datatype:
This implies that no square brackets may occur within LOTS OF DATA.
You could even spare the trailing 'datatype:' match.
Should LOTS OF DATA contains square brackets you would have to come up with a more precise specification of its content.

Bug in my regular expression

I'm trying to look at a string and reject anything that has seq= or app= in the string. Where it gets tricky is I need elements with q=something or p=something.
The seq= part of the string is always preceded an & and app= is always preceded by a ?
I have absolutely no idea where to start. I've been using http://www.rubular.com/ to try and figure it out but to no avail.
Any help would be hugely appreciated.
Based on your question, I believe you could just reject any strings that match the following expression:
[\?&](?:seq|app)=
This will match any string that contains a ? or & followed by either app= or seq=. The ?: inside the parentheses just tells the regular expression not to bother to capture matching groups as sub-matches. They're not really necessary, but what the heck.
Here's a Rubular link with some samples.

Delphi: What is the escape character in filter string of a Data access such as TVirtualTable

I am trying a build a filter string for a Virtual table and would like underscore (_) to be a literal character and cannot figure out the escape character. Following are few that I tried and failed miserably:
VTAllDocs.Filter :='FILE_NAME like '+QuotedStr(MQDRegister.FieldByName('DOC_ID').AsString+'%\_REV%');
AND
VTAllDocs.Filter :='FILE_NAME like '+QuotedStr(MQDRegister.FieldByName('DOC_ID').AsString+'%[_]REV%');
AND
VTAllDocs.Filter :='FILE_NAME like '+QuotedStr(MQDRegister.FieldByName('DOC_ID').AsString+'*\_REV*');
AND
VTAllDocs.Filter :='(FILE_NAME like '+QuotedStr(MQDRegister.FieldByName('DOC_ID').AsString+'%^_REV%)+' ESCAPE "^")';
Really appreciate your help.
Thank you.
Never mind..
Contacted DevArt support desk and they said there is no escape character for underscore (_), so now I loop through the rows and do the checking manually.

string format checking (with partly random string)

I would like to use regular expression to check if my string have the format like following:
mc_834faisd88979asdfas8897asff8790ds_oa_ids
mc_834fappsd58979asdfas8897asdf879ds_oa_ids
mc_834faispd8fs9asaas4897asdsaf879ds_oa_ids
mc_834faisd8dfa979asdfaspo97asf879ds_dv_ids
mc_834faisd111979asdfas88mp7asf879ds_dv_ids
mc_834fais00979asdfas8897asf87ggg9ds_dv_ids
The format is like mc_<random string>_oa_ids or mc_<random string>_dv_ids . How can I check if my string is in either of these two formats? And please explain the regular expression. thank you.
That's a string start with mc_, while end with _oa_ids or dv_ids, and have some random string in the middle.
P.S. the random string consists of alpha-beta letters and numbers.
What I tried(I have no clue how to check the random string):
/^mc_834faisd88979asdfas8897asff8790ds$_os_ids/
Try this.
^mc_[0-9a-z]+_(dv|oa)_ids$
^ matches at the start of the line the regex pattern is applied to.
[0-9a-z] matces alphabetic and numeric chars.
+ means that there should be one or more chars in this set
(dv|oa) matches dv or oa
$ matches at the end of the string the regex pattern is applied to.
also matches before the very last line break if the string ends with a line break.
Give /\Amc_\w*_(oa|dv)_ids\z/ a try. \A is the beginning of the string, \z the end. \w* are one or more of letters, numbers and underscores and (oa|dv) is either oa or dv.
A nice and simple way to test Ruby Regexps is Rubular, might have a look at it.
This should work
/mc_834([a-z,0-9]*)_(oa|dv)_ids/g
Example: http://regexr.com?2v9q7

Regular expression in Ruby

Could anybody help me make a proper regular expression from a bunch of text in Ruby. I tried a lot but I don't know how to handle variable length titles.
The string will be of format <sometext>title:"<actual_title>"<sometext>. I want to extract actual_title from this string.
I tried /title:"."/ but it doesnt find any matches as it expects a closing quotation after one variable from opening quotation. I couldn't figure how to make it check for variable length of string. Any help is appreciated. Thanks.
. matches any single character. Putting + after a character will match one or more of those characters. So .+ will match one or more characters of any sort. Also, you should put a question mark after it so that it matches the first closing-quotation mark it comes across. So:
/title:"(.+?)"/
The parentheses are necessary if you want to extract the title text that it matched out of there.
/title:"([^"]*)"/
The parentheses create a capturing group. Inside is first a character class. The ^ means it's negated, so it matches any character that's not a ". The * means 0 or more. You can change it to one or more by using + instead of *.
I like /title:"(.+?)"/ because of it's use of lazy matching to stop the .+ consuming all text until the last " on the line is found.
It won't work if the string wraps lines or includes escaped quotes.
In programming languages where you want to be able to include the string deliminator inside a string you usually provide an 'escape' character or sequence.
If your escape character was \ then you could write something like this...
/title:"((?:\\"|[^"])+)"/
This is a railroad diagram. Railroad diagrams show you what order things are parsed... imagine you are a train starting at the left. You consume title:" then \" if you can.. if you can't then you consume not a ". The > means this path is preferred... so you try to loop... if you can't you have to consume a '"' to finish.
I made this with https://regexper.com/#%2Ftitle%3A%22((%3F%3A%5C%5C%22%7C%5B%5E%22%5D)%2B)%22%2F
but there is now a plugin for Atom text editor too that does this.

Resources