string-matching
Find the Number of Occurrences of a Substring in a String
How about using StringUtils.countMatches from Apache Commons Lang? String str = “helloslkhellodjladfjhello”; String findStr = “hello”; System.out.println(StringUtils.countMatches(str, findStr)); That outputs: 3
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 … Read more
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 … Read more
Regular Expression Arabic characters and numbers only
Just add 1-9 (in Unicode format) to your character-class: ^[\u0621-\u064A0-9 ]+$ OR add \u0660-\u0669 to the character-class which is the range of Arabic numbers : ^[\u0621-\u064A\u0660-\u0669 ]+$
How to check if matching text is found in a string in Lua?
There are 2 options to find matching text; string.match or string.find. Both of these perform a regex search on the string to find matches. string.find() string.find(subject string, pattern string, optional start position, optional plain flag) Returns the startIndex & endIndex of the substring found. The plain flag allows for the pattern to be ignored and … Read more
javascript regular expression to check for IP addresses
May be late but, someone could try: Example of VALID IP address 115.42.150.37 192.168.0.1 110.234.52.124 Example of INVALID IP address 210.110 – must have 4 octets 255 – must have 4 octets y.y.y.y – only digits are allowed 255.0.0.y – only digits are allowed 666.10.10.20 – octet number must be between [0-255] 4444.11.11.11 – octet … Read more
Filter multiple values on a string column in dplyr
You need %in% instead of ==: library(dplyr) target <- c(“Tom”, “Lynn”) filter(dat, name %in% target) # equivalently, dat %>% filter(name %in% target) Produces days name 1 88 Lynn 2 11 Tom 3 1 Tom 4 222 Lynn 5 2 Lynn To understand why, consider what happens here: dat$name == target # [1] FALSE FALSE FALSE … Read more
Regular Expression Match to test for a valid year
Years from 1000 to 2999 ^[12][0-9]{3}$ For 1900-2099 ^(19|20)\d{2}$