Search by regular pattern in iOS [duplicate] - objective-c

This question already has answers here:
What's the regular expression that matches a square bracket?
(10 answers)
Closed 3 years ago.
Trying to search bbcode-style tags with regular expression:
For example, I needed [user=1]John Dow[/user] with regular: [[user=[0-9]+].*?[/user]]
But couldn't receive needed result.

Remove the outer pair of brackets and escape the literal brackets (unlike the range-of-characters brackets)
let pattern = "\\[user=[0-9]+\\].*?\\[/user\\]"

Related

decode this regex [duplicate]

This question already has answers here:
What do comma separated numbers in curly braces at the end of a regex mean?
(6 answers)
Closed 3 years ago.
I've tried to understand the below but don't seem to get the last part of the regular expression which has {1,40}. Overall, I know the pattern tries to match the special characters and something else (the {1,40})
regexp_like(COLUMN,'^['||UNISTR('\0020')||'-'||UNISTR('\0060')||UNISTR('\007B')||UNISTR('\007D')||UNISTR('\007E')||UNISTR('\00C0')||'-'||UNISTR('\00DF')||']'||'{1,40}$')
regexp_like() checks that a string matches the regex provided as second argument.
Your regexp looks like ^[...]{1,40}$.
^ is the beginning of the string and $ is the end, so the entire string must match the regex.
[...] is a character class, that contains a bunch of characters code points. All characters of the string must belong to that list (any other character is forbiden). You would need to to check what they correspond to: unicode.org is your friend. For the first code points:
\0020 space
\0060 grave accent
\007B left curly bracket
finally, {1,40} is a quantifier: the length of the string must be at least one and at most 40.

Delete Pandas DataFrame row if contains character [duplicate]

This question already has answers here:
how to search character plus using pandas.Series.str.contains
(1 answer)
Pandas Python Regex : error: nothing to repeat
(3 answers)
Pandas not counting rows properly
(3 answers)
Closed 4 years ago.
I'm trying to remove any row that contains a "?" in a particular column.
I have this line:
df[~df.C.str.contains("?")]
which doesn't work. I get the following error:
error: nothing to repeat at position 0
However the following does work
df[~df.C.str.contains("abc")]
Does anyone know what it is about ? that stops it running?
.str.contains() expects a regular expression by default; ? is treated as a metacharacter, and using it alone will raise re.error.* Pass regex=False to search for a literal "?" character:
df[~df.C.str.contains("?", regex=False)]
* See re.compile("?")

Caret in SQL Regular Expressions [duplicate]

This question already has answers here:
Carets in Regular Expressions
(2 answers)
Closed 6 years ago.
I'm studying regular expressions and cannot figure out what this caret does exactly. I thought that this caret symbol means 'not equal', but in this query below, I am confused:
SELECT REGEXP_REPLACE('San Antonio', '(^[[:alpha:]]+)', 'CITY') TEST
FROM DUAL;
RESULT:
CITY Antonio
'San' should comply with [:alpha:] so I don't understand what the caret function does here.
Carrat (^) also stands for the beginning of the line (and Dollar ($) for its end).
^Hello$ = the word Hello and nothing more
^Hello.* = something that starts with Hello
The negation functionality is within square brackets:
[^0-9] = anything that is not a digit
[^a-zA-Z] = anything that is not an english letter
Caret ^ (please note the correct spelling) means "at the beginning of the string", but only when it is the very first character in the matching pattern.
'San' does NOT comply with [:alpha:], because [:alpha:] is a SINGLE alphabetic character. [ ... ] means "matching set" (match exactly ONE SINGLE character of those listed within square brackets). [[:alpha:]] means any single alphabetic character. The + means "one or more" of what precedes it, so 'San' matches [[:alpha:]]+ at the beginning of the string. 'Antonio' also matches, but it is not at the beginning of the string, so it is not replaced. If you didn't have the caret, both words would be replaced with CITY (try it and you will see.)

Print double quote inside #"" [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to escape double quotes in string?
I need to print a "abc" inside #""
My current string is
[displayLbl setText:#"press stop"];
But i need:
[displayLbl setText:#"press "stop""];
How can i do this?
[displayLbl setText:#"press \"stop\""];
Roland Keesom's answer is of course correct. But you might also consider to use typographic quotation marks, which usually look better:
[displayLbl setText:#"press “stop”"];
(You only have to find them on the keyboard (-: )

VB.NET function for uppercasing the first letter of each word [duplicate]

This question already has answers here:
How to uppercase the first character of each word using a regex in VB.NET?
(9 answers)
Closed 8 years ago.
I'm looking for do this in VB.NET,
hy how are you
to,
Hy How Are You
Anyone have any idea?
This following will do what you want without using regex (and is more readable than a regex solution):
Dim s As String = "some sentence that i want to capitalise"
Debug.WriteLine(Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s))
Output:
Some Sentence That I Want To Capitalise
And you can also do this (from the Microsoft.VisualBasic Namespace):
Debug.WriteLine(StrConv(s, VbStrConv.ProperCase))
You can do that using regular expressions. There are a useful class named Regex that will help you a lot. Please follow this link for more information.