I'm fighting for some time to create a QRegExp for matching the string (??) (ie: an opening parantheses, two question marks and a closing parantheses and this should be a separate word, so before and after this can be spaces, tab, newline), The closest I came up with is QRegExp("\\b\\(\\?\\?\\)\\b"); but even this is not matching it... Can you help me with this?
Thanks
f.
I don't know QRegexp, but \b only matches between alphanumeric and non-alphanumeric characters, so your regex would match (??) only if it was directly surrounded by alnums (like abc(??)123).
So you need a different approach. Hoping QRegexp supports lookaround, you could use
QRegExp("(?<=\\s|^)\\(\\?\\?\\)(?=\\s|$)");
so the regex checks if there is whitespace or start/end of string before/after (??).
If that doesn't work, you'll have to match the whitespace explicitly:
QRegExp("(?:\\s|^)\\(\\?\\?\\)(?:\\s|$)");
You could try with \B instead of \b:
QRegExp("\\B\\(\\?\\?\\)\\B");
Related
I want the regex not to be recognized, should be a special character before, between and after the regex.
My Regex:
\b([t][\W_]*?)+([e][\W_]*?)+([s][\W_]*?)+([t][\W_]*?)*?\b
https://regex101.com/r/zKg2eR/1
Example:
#test, te+st, t'est or =test etc.
I hope I could bring it across reasonably understandable.
If you want to match a word character excluding an underscore, you can write it as [^\W_] using a negated character class.
You don't need a character class for a single char [t] and you are repeating the groups as well, which you don't have to when you want to match a form of test
If the words are on a single line, you can append anchors ^ and $
^(t[^\W_]*)(e[^\W_]*)(s[^\W_]*)(t[^\W_]*)$
Regex demo
As you selected golang in the regex tester, you can not use lookarounds. Instead you can use an alternation to match either a whitespace char or the start/end of the string.
Then capture the whole match in another capture group.
(?:^|\s)((t[^\W_]*)(e[^\W_]*)(s[^\W_]*)(t[^\W_]*))(?:$|\s)
Regex demo
I am trying to write a pattern that matches {^xyz^} as bellow,
#"\b\{\^\S*\^\}\b
But I am not getting success and wondering what is problem with my pattern.
You can use:
#"\{\^([^}]*)\^\}"
and extract captured group #1 for your string.
Use a captured group to get the substring you want to extract from a larger match.
Word boundaries or \b won't work here because { and } are non-word characters.
Use of negated character class [^}]* is more efficient and accurate than greedy \S*.
I would simply use \{\^(\S*?)\^\}. This way you are capturing the contents between the carets and curly brackets. The ? is to make the * quantifier lazy, so it matches as little characters as possible (in order to prevent matching the beginning of one block until the end of another block in the same line).
With those \b you need a word-type character right before and after the curly braces for the regex to match. Is that really a requirement? Or can there be a space?
I'm trying to match the three first text lines in regex, i.e. the ones ending with form.
value="something form"
value="Second cool form"
value="another silly old form"
value="blabla"
How can I do that?
I don't know what tool you are using, but the following pattern should match the first three lines:
.*form"$
Demo
You could simply use:
.*form"$
In order to work, you would have to turn on multiline mode.
Dot (.) means - match me anything but newline character, asterisk (*) means - match me dot zero or more times after which comes text form. Dollar sign ($) is anchor to the string ending.
Take a look at demo. You should learn more about regular expressions here, this is basic regex matching.
You can try using this:
\w*form\b
\w*: Allows characters in front of form
\b: Makes sure that form is at the end of the string.
Regex 101 demo
Actually if you want to match the 'form' as a separate word, you need something like this:
\Wform\W
\W (capital W) is any character which does not represent a word character, at least in perl-like regex.
How can I match all characters including new line with a regex.
I am trying to match all characters between brackets "()". I don't want to activate Dot matches all.
I tried
\([.\n\r]*\)
But it doesn't work.
(.*\) This doesn't work if there is an new line between the brackets.
I have been using http://regexpal.com/ to test my regular expressions. Tell me if you know something better.
I'd usually use something like \([\S\s]*\) in this situation.
The [\S\s] will match any whitespace or non-whitespace character.
The first example doesn't work because inside a character class the dot is treated literally (Matches the . character instead of all characters).
\((.|[\n\r])*\)
I have a situation where using VBScript I need to check for the presence of multiple spaces.
I want to check for the presence of 2 or more consecutive spaces, so \s+ doesnt work for my needs.
Does anyone know how I can accomplish this using VBScript regular expressions.
Use brackets to specify how many repetitions to match. This matches two or more whitespace characters:
\s{2,}
If you want to match only space characters, just use a space instead of \s, or the character code:
\x20{2,}
This ought to do the trick:
\s{2,}