regex

RegEx in Angular 2 Form Validators producing different results when argument is a String vs a RegExp class

☆樱花仙子☆ 提交于 2021-02-16 19:04:11
问题 I'm attempting to validate a basic form element using Angular 2 Form Validators, and the RegEx I'm placing in to Validators.pattern() to match a valid URL is matching patterns that theoretically aren't valid when the argument is a String data type. // example.component.ts this.exampleForm = fb.group({ // The patterns below will match most URL structures, and are exactly the same const reg = '^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$'; const patt = new RegExp(/^(https?:\/\

RegEx in Angular 2 Form Validators producing different results when argument is a String vs a RegExp class

百般思念 提交于 2021-02-16 19:03:54
问题 I'm attempting to validate a basic form element using Angular 2 Form Validators, and the RegEx I'm placing in to Validators.pattern() to match a valid URL is matching patterns that theoretically aren't valid when the argument is a String data type. // example.component.ts this.exampleForm = fb.group({ // The patterns below will match most URL structures, and are exactly the same const reg = '^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$'; const patt = new RegExp(/^(https?:\/\

RegEx in Angular 2 Form Validators producing different results when argument is a String vs a RegExp class

萝らか妹 提交于 2021-02-16 19:03:29
问题 I'm attempting to validate a basic form element using Angular 2 Form Validators, and the RegEx I'm placing in to Validators.pattern() to match a valid URL is matching patterns that theoretically aren't valid when the argument is a String data type. // example.component.ts this.exampleForm = fb.group({ // The patterns below will match most URL structures, and are exactly the same const reg = '^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$'; const patt = new RegExp(/^(https?:\/\

Regex - How to remove strings inside brackets?

和自甴很熟 提交于 2021-02-16 19:01:23
问题 I want to remove all words inside brackets and square brackets. I'm using this regex, but it only removes words inside brackets. It does not work with square brackets... var str = 'hey [xx] (xhini) rexhin (zzz)'; var r = str.replace(/ *\([^)]*\)*\] */g, ''); r should be hey rexhin Any suggestions? 回答1: You can use this regex: var str = 'hey [xx] (xhini) rexhin (zzz)'; var r = str.replace(/(\[.*?\]|\(.*?\)) */g, ""); //=> hey rexhin \[.*?\] will find square brackets and string inside them \(.*

Remove all spaces before and after parentheses

浪子不回头ぞ 提交于 2021-02-16 18:53:27
问题 I would like to remove one or more spaces before and after any parentheses. Following this post where the issue has been solved for PHP with the following regex (?<=[([]) +| +(?=[)\]]) now I would like to do the same in Javascript but Javascript regex engine does not have the same lookahead and lookbehind as PHP. I managed to make the following regex at least work in Javascript but it removes all spaces: ?![([]) +| +(?=[)\]]) See Regex101 test. Given string: This is ( a sample ) [ string ] to

How to grep an exact string with slash in it?

谁说胖子不能爱 提交于 2021-02-16 18:24:12
问题 I'm running macOS. There are the following strings: /superman /superman1 /superman/batman /superman2/batman /superman/wonderwoman /superman3/wonderwoman /batman/superman /batman/superman1 /wonderwoman/superman /wonderwoman/superman2 I want to grep only the bolded words. I figured doing grep -wr 'superman/|/superman' would yield all of them, but it only yields /superman. Any idea how to go about this? 回答1: You may use grep -E '(^|/)superman($|/)' file See the online demo: s="/superman

Regex - Matching exactly one single tag

怎甘沉沦 提交于 2021-02-16 18:24:08
问题 I have a regex to extract the text from an HTML font tag: <FONT FACE=\"Excelsior LT Std Bold\"(.*)>(.*)</FONT> That's working fine until I have some nested font tags. Instead of matching <FONT FACE="Excelsior LT Std Bold">Fett</FONT> the result for string <FONT FACE="Excelsior LT Std Bold">Fett</FONT> + <U>Unterstrichen</U> + <FONT FACE="Excelsior LT Std Italic">Kursiv</FONT> und Normal is <FONT FACE="Excelsior LT Std Bold">Fett</FONT> + <U>Unterstrichen</U> + <FONT FACE="Excelsior LT Std

How to grep an exact string with slash in it?

两盒软妹~` 提交于 2021-02-16 18:24:05
问题 I'm running macOS. There are the following strings: /superman /superman1 /superman/batman /superman2/batman /superman/wonderwoman /superman3/wonderwoman /batman/superman /batman/superman1 /wonderwoman/superman /wonderwoman/superman2 I want to grep only the bolded words. I figured doing grep -wr 'superman/|/superman' would yield all of them, but it only yields /superman. Any idea how to go about this? 回答1: You may use grep -E '(^|/)superman($|/)' file See the online demo: s="/superman

How to use regex for matching multiple words

拜拜、爱过 提交于 2021-02-16 18:13:19
问题 How can I use regex to match multiple words in java? For example, the addAction("word") and intentFilter("word") at the same time for matching? I tried: string REGEX ="[\\baddAction\\b|\\bintentFilter\\b]\\s*\([\"]\\s*\\bword\\b\\s*[\"]\)"; Could someone tell me what's wrong with this format and how can I fix it? 回答1: You are trying to use alternative lists in a regex, but instead you are using a character class ( "[\\baddAction\\b|\\bintentFilter\\b] ). With a character class, all characters

Conditional Replace with Visual Studio

拟墨画扇 提交于 2021-02-16 17:58:09
问题 In Visual Studio, I need to substitute a word with another, preserving the first character case. For example I need to subsitute "Bob" with "James" and "bob" with "james" at once, and I must avoid to replace partial matches like "ob" with "james" or "James". This can be done e.g. in Notepad++ with find:"((b)|(B))ob", replace: "(?2j:?3J)ames"; unfortunately this does not work in Visual Studio (I'm using 2015). Is it possible to do this in Visual Studio? Thanks. 回答1: It is not possible with