[Solved] Regexp – Delete the one word before XXX, remove XXX too [closed]

Do a single regex replacement: string input = @”Hello World XXX Goodbye XXX Rabbit!”; Regex rgx = new Regex(@”\s*\w+\s+(?:XXX|xxx)”); // or maybe [Xx]{3} string result = rgx.Replace(input, “”, 1); Console.WriteLine(result); Hello Goodbye XXX Rabbit! Demo This replacement only would target XXX for removal if it be preceded by a word (one character or more). Explore … Read more

[Solved] Separate string in Python [closed]

You can use regular expressions: import re s = [el for el in re.split(‘([\W+])’, ‘☕ Drink the ❶ best ☕coffee☕’) if el.strip()] print(s) output: [‘☕’, ‘Drink’, ‘the’, ‘❶’, ‘best’, ‘☕’, ‘coffee’, ‘☕’] 2 solved Separate string in Python [closed]

[Solved] replace the same occurring number with another random number [closed]

I didn’t really get what you mean, but if you want to replace a specific text in your file with a random integer then try: import fileinput from random import randint with fileinput.FileInput(fileToSearch, inplace=True, backup=’.bak’) as file: for line in file: print(line.replace(textToSearch, textToReplace), end=”) with textToReplace = randint(1990, 2020) Hope that helps 7 solved replace … Read more

[Solved] How can I extract an actual URL from a string? [duplicate]

No need to write a regex when the ability to parse URLs already exist. MDN: Web technology for developers > See Web APIs > URL const url = new URL(“https://stackoverflow.com/questions/ask”); console.log(`${url.origin}`); // Includes port console.log(`${url.protocol}//${url.hostname}`); // Alternatively… 2 solved How can I extract an actual URL from a string? [duplicate]

[Solved] What will be the regex for the given case? [closed]

You want that $ in either case. Instead of ‘slash OR end’, it’s more ‘optional slash and then a very much not-optional end’. So.. /?$. You don’t need to normally escape slashes, especially in java regexes: Pattern.compile(“[-/](\\d+)/?$”) This reads: From minus or slash, a bunch of digits, then 0 or 1 slashes, then the end. … Read more

[Solved] Can’t figure out why match result is nil [closed]

Regex is the wrong tool for handling HTML (or XML) 99.9% of the time. Instead, use a parser, like Nokogiri: require ‘nokogiri’ html=”<img src=”https://filin.mail.ru/pic?width=90&amp;height=90&amp;email=multicc%40multicc.mail.ru&amp;version=4&amp;build=7″ style=””>” doc = Nokogiri::HTML(html) url = doc.at(‘img’)[‘src’] # => “https://filin.mail.ru/pic?width=90&height=90&email=multicc%40multicc.mail.ru&version=4&build=7” doc.at(‘img’)[‘style’] # => “” Once you’ve retrieved the data you want, such as the src, use another “right” tool, such as … Read more

[Solved] How to split multiple string formats using regex and assigning its different groups to variable [closed]

You can use this code: import re domain = “collabedge-123.dc-01.com” # preg_match(“/^(collabedge-|cb|ss)([0-9]+).dc-([0-9]+).com$/”, $domain, $matches); regex = r”^(collabedge-|cb|ss)([0-9]+).dc-([0-9]+).com$” res = re.match(regex,domain) print(res.group(0)) print(res.group(1)) print(res.group(2)) print(res.group(3)) Output: collabedge-123.dc-01.com collabedge- 123 01 1 solved How to split multiple string formats using regex and assigning its different groups to variable [closed]

[Solved] Regex to split string into array of numbers and characters using PHP

Use this regex :(?<=[()\/*+-])(?=[0-9()])|(?<=[0-9()])(?=[()\/*+-]) It will match every position between a digit or a parenthesis and a operator or a parenthesis.(?<=[()\/*+-])(?=[0-9()]) matches the position with a parenthesis or an operator at the left and a digit or parenthesis at the right(?<=[0-9()])(?=[()\/*+-]) is the same but with left and right reversed. Demo here 5 solved Regex … Read more

[Solved] Python: Find a Sentence between some website-tags using regex

If you must do it with regular expressions, try something like this: a = re.finditer(‘<a.+?question-hyperlink”>(.+?)</a>’, html) for m in a: print m.group(1) Just for the reference, this code does the same, but in a far more robust way: doc = BeautifulSoup(html) for a in doc.findAll(‘a’, ‘question-hyperlink’): print a.text solved Python: Find a Sentence between some … Read more

[Solved] Regex to replace function foo(a,b) to function foo(b,a) [closed]

Search for (with regex setting turned on) BeanUtils\.copyProperties\s*\(\s*([\w\_]+)\s*\,\s*([\w\_]+)\s*\)\s*\; And replace with: BeanUtils.copyProperties($2, $1); First escape all literal characters with backslash \ Wherever a space can be found when writing code, match it with 0 or more spaces. That by using \s* Could use [ ]* but \s might be sufficient in this case. Then add … Read more

[Solved] Textarea hashtag highlight is applied to the wrong position after the first line [closed]

The problem you’re facing here is that your regex is replacing newline characters with a space before the final replacement of newline characters by <br /> elements occurs. As a result, in cases where your hashed string is preceded by a newline, the highlight will appear on the previous line, rather than correctly being placed … Read more