[Solved] REGEX with two capturing groups

You can use this regex: <result1>(.*?)<result1>(?:(?:.(?!<result1>))*?<result>(.*?)<result>)? Can get your text in group #1 and group #2 (if exists). This regex will give: MATCH 1 1. `A1` 2. `B1` MATCH 2 1. `A2` MATCH 3 1. `A3` 2. `B3` RegEx Demo solved REGEX with two capturing groups

[Solved] TypeError: unsupported operand type(s) for &: ‘str’ and ‘int’ on compile re [closed]

You are calling the re.compile() function, whose second argument is an integer representing the different regular expression flags (such as IGNORECASE or VERBOSE). Judging by your variable names, I think you wanted to use the re.findall() function instead: findall_localizacao_tema = re.findall( ‘:.? (*)’ + findall_tema[0] + “https://stackoverflow.com/”, arquivo_salva) You can still use re.compile, but then … Read more

[Solved] Read file content and use Regular Expression to locate a pattern in each File in Perl

use strict; use warnings; use HTML::TreeBuilder::XPath; my ($dir) = @ARGV; my @files = glob “$dir/*”; for my $file (@files) { my $tree = HTML::TreeBuilder::XPath->new_from_file($file); my @opacity = $tree->findnodes_as_strings(‘//div[@class=”opacity description”]’); print “\n$file\n”; print ” $_\n” for @opacity; } solved Read file content and use Regular Expression to locate a pattern in each File in Perl

[Solved] How can I read this string in Java? [closed]

Here are several ways to get the first character: String str = “x , y – zzzzzz”; System.out.println(str.charAt(0)); System.out.println(str.substring(0, 1)); System.out.println(str.replaceAll(“^(.).*”, “$1”)); See IDEONE demo Choose the one you like more 🙂 UPDATE: To find the first word, you may use the following regex pattern: String pattern = “[\\s\\p{P}]+”; \s stands for whitespace, and \p{P} … Read more

[Solved] Regex to allow PhoneNumber with country code

\+\d{1,4}-(?!0)\d{1,10}\b Breakdown: \+ Match a literal + \d{1,4} Match between 1 and 4 digits inclusive – Match a literal – (?! Negative lookahead, fail if 0 this token (literal 0) is found ) \d{1,10} Match between 1 and 10 digits inclusive \b Match a word boundary Demo (with your examples) var phoneRegexp = /\+\d{1,4}-(?!0)\d{1,10}\b/g, tests … Read more

[Solved] How to extract an alphanumeric string from a sentence if a starting point and end point is given [closed]

Using regex Code import re def extract(text): ”’ extract substring ”’ pattern = r’^G.*[794]’ # pattern ends in 7, 9, 4 # Find pattern in text m = re.match(pattern, text) # find pattern in string if m: # Found pattern substring # Remove space, \, (, – by replacing with empty string m = re.sub(r'[ … Read more

[Solved] The regular expression error is malformed

I guess, it means that you must escape the character ‘-‘ by writing ‘\-‘ within the regular expression, when it’s not used as a range indicator. Try to change: ‘.+@^[A-Za-z0-9.-]+\.^[A-Za-z]{2,4}’ by ‘.+@^[A-Za-z0-9.\-]+\.^[A-Za-z]{2,4}’ As @Fallenhero stated. The ‘^’ seem also to be misplaced somehow. 1 solved The regular expression error is malformed

[Solved] Extract numbers, letters, or punctuation from left side of string column in Python

Use Series.str.extract with DataFrame.pop for extract column: pat = r'([\x00-\x7F]+)([\u4e00-\u9fff]+.*$)’ df[[‘office_name’,’company_info’]] = df.pop(‘company_info’).str.extract(pat) print (df) id office_name company_info 0 1 05B01 北京企商联登记注册代理事务所(通合伙) 1 2 Unit-D 608 华夏启商(北京企业管理有限公司) 2 3 1004-1005 北京中睿智诚商业管理有限公司 3 4 17/F(1706) 北京美泰德商务咨询有限公司 4 5 A2006~A2007 北京新曙光会计服务有限公司 5 6 2906-10 中国建筑与室内设计师网 11 solved Extract numbers, letters, or punctuation from left side of string … Read more

[Solved] Extract certain substring in Java

String method: Use StringUtils.substringBetween() of Apache Commons: public static void main(String[] args) { String sentence = “User update personal account ID from P150567 to A250356.”; String id = StringUtils.substringBetween(sentence, “from “, ” to”); System.out.println(id); } Regex method: Use regex from (.*) to, the string surrounded by parentheses is called group(1), just extract it: public static … Read more

[Solved] How do you match valid integers and roman numerals with a regular expression?

Assuming that you just want decimal integers in regular form (e.g., 1000 would be valid, 1e3 [the same number in scientific notation] would not), the regular expression to validate that is \d+, which means “one or more digit(s).” To have your regular expression allow that, you’d want an alternation, which lets either of two alternatives … Read more

[Solved] Please check my Regex to match color text [closed]

but i have a problem whit performance this.Dispatcher.Invoke invokes back to the GUI thread…which doesn’t do any good if you want the work to not hamper the user. You need to separate out the what the regex’es find, from the how to display it to the user. Running the regex’es in separate threads is a … Read more

[Solved] More than one preg_match queries? [closed]

if(preg_match($fullname_pattern,$fullname)) Remove Last “)” And add here (preg_match($password_pattern,$password))) Like this: if(preg_match($fullname_pattern,$fullname) && preg_match($email_pattern,$email) && preg_match($password_pattern,$password) ) { 1 solved More than one preg_match queries? [closed]