This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Split on substring
I want to separate an std::string by a two character separator, i.e. I'm looking for string tokenizer that can accept separators which are NOT a single character. Boost's tokenizer allows for multiple characters to be specified as separators, but this means that it'll consider any individual character as a separator, whilst what I want is to say that the separator is a particular sequence of characters, viz. a substring.
I'd initially thought I would quickly find the answer to this with a couple of google searches, but having just been proven wrong by a couple of wasted hours, I ask: ideas anyone?
QT's QString::split() can do this.
Related
This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 3 years ago.
Regex testing for special characters, decimal except for hyphen, commas, alpha-numeric.
Attempt
^(\+|-)?([0-9]+)$/
I'm trying to write a regex to match special characters, decimal except for commas, a hyphen, alpha-numeric.
Welcome!
Maybe, you might just want to list the chars that you wish in a [] and test it. Maybe, a simple expression like this would be desired for you and you could work on it:
^([?!"'~&%$*##0-^#9]+)$
You might want to use this tool and design an expression that you wish, then test it with real samples and maybe change it as you wish.
You can also use an online visualizer to view how your expression would work:
This question already has answers here:
How do I match any character across multiple lines in a regular expression?
(26 answers)
Regex search with pattern containing (?:.|\s)*? takes increasingly long time
(1 answer)
Closed 3 years ago.
A few times I saw regex experts say that using (.|\n)*? is a really, really bad idea.
Well, I do understand that it's better to replace it with the .* and use the /s flag. But sometimes the flags are not available, for example, when using regex within a text editor or other software with limited regex functionality. Thus, using something like (.|\n)*? might be the only option for multi-line matching.
So, what are the reasons to always avoid (.|\n)*??
This question already has answers here:
Find shortest matches between two strings
(4 answers)
Closed 4 years ago.
This is a simple question of the Theory of Computation.
I don't know nor want the python coded interpretation of this but rather the theoretical answer of the expression.
I have tried my best to figure it out and came up with the below code:
(ab+ba+bb)*. aa.(ab+ba+bb)*.aa.(ab+ba+bb)* + b*.aa.b*.aa.b*
Is it right? Am I forgetting any other case?
Your regex is too complicated and not very flexible (it only works with strings of a and b). A better solution uses negative look-ahead assertions:
^(?:(?!aa).)*aa(?:(?!aa).)*aa(?:(?!aa).)*$
This looks for any length of substring at the start of the string that does not contain aa, then the first aa, and so on.
This question already has answers here:
How do I isolate a space using RegExp in VBA (\s vs. \p{Zs})?
(3 answers)
Closed 4 years ago.
I am having a similar issue as this question here. \s is not matching all white spaces in VBA.
But I want to catch all kinds of whitespace - spaces, tabs, newlines, thin space, hair space etc. and not only one of them.
Is there another possibility than hard coding every unicode value like the following?
With regEx
.Global = True
.Pattern = "(\s|\u2009|\u2008|.............)"
End With
How do I isolate a space using RegExp in VBA (\s vs. \p{Zs})? wants to isolate spaces - I want readable and reliable way to match any whitespace without needing to list the unicode values for them as proposed by the one who closed the question.
There is no perfect alternative, therefore I suggest to use exact values/codes.
You should be safe with this regex pattern:
[\s\n\r\t \xA0\u1680\u180E\u2000-\u200B\u202F\u205F\u3000\uFEFF]+
This question already has answers here:
Using Regex to generate Strings rather than match them
(12 answers)
Reverse regular expression, create string from regex
(1 answer)
Closed 9 years ago.
Or "How can I RegEx in reverse?"
specifically I want to take a regex such as wks[0-9][0-9][0-9]
and create a list such as wks001,wks002,wks003, etc
I know the easiest way in this example would be to simply increment the number through addition, but say I want it to be even more sophisticated later on such as [0-9abc] I'd like to use a more sophisticated tool.
preferable would be some windows capable scripting tech, such as vbscript/powershell but I'm open to other alternatives. I guess I kind of thought this might be something that is done all the time by random number generators and such and would be a programming staple, but I lack the understanding to phrase it correctly I think.