string-matching
Pandas text matching like SQL’s LIKE?
You can use the Series method str.startswith (which takes a regex): In [11]: s = pd.Series([‘aa’, ‘ab’, ‘ca’, np.nan]) In [12]: s.str.startswith(‘a’, na=False) Out[12]: 0 True 1 True 2 False 3 False dtype: bool You can also do the same with str.contains (using a regex): In [13]: s.str.contains(‘^a’, na=False) Out[13]: 0 True 1 True 2 …
Most efficient way to check if $string starts with $needle in perl
rindex $string, $substring, 0 searches for $substring in $string at position <=0 which is only possible if $substring is a prefix of $string. Example: > rindex “abc”, “a”, 0 0 > rindex “abc”, “b”, 0 -1
Are Regular Expressions a must for programming? [closed]
One could easily go without them but one should (IMHO) know the basics, for 2 reasons. 1) There may come a time where RegEx is the best solution to the problem at hand (see image below) 2) When you see a Regex in someone else’s code it shouldn’t be 100% mystical. preg_match(‘/summarycount”>.*?([,\d]+)<\/div>.*?Reputation/s’, $page, $rep); This …
Perl – If string contains text?
If you just need to search for one string within another, use the index function (or rindex if you want to start scanning from the end of the string): if (index($string, $substring) != -1) { print “‘$string’ contains ‘$substring’\n”; } To search a string for a pattern match, use the match operator m//: if ($string …
How to do whole-word search similar to “grep -w” in Vim
\<bar\> matches bar but neither foobar nor barbaz nor foobarbaz. Use it like this in a substitution: :s/\<bar\>/baz Use it like this to list all the lines containing the whole word bar: :g/\<bar\> :h pattern is a good read.
Regex allow a string to only contain numbers 0 – 9 and limit length to 45
You are almost there, all you need is start anchor (^) and end anchor ($): ^[0-9]{1,45}$ \d is short for the character class [0-9]. You can use that as: ^\d{1,45}$ The anchors force the pattern to match entire input, not just a part of it. Your regex [0-9]{1,45} looks for 1 to 45 digits, so …