regex

regex to match non-latin char with ASCII 0-31 and 128-255

柔情痞子 提交于 2021-02-16 20:33:08
问题 wanted to match the non-latin char. tried it. as per my understanding if (a.matches("[\\x8A-\\xFF]+")) should return true but its false. String a = "Ž"; if (a.matches("[\\x8A-\\xFF]+")) { } 回答1: Judging from your title: Regex to match non-latin char with ASCII 0-31 and 128-255 it seems you're after all characters except those in range 32-127 and you're surprised Ž doesn't match. If this is correct, I suggest you use the expression [^\x20-\x7F] ( "all characters except those in range 32-127" )

Replace curly braced expression with one item from the expression

蹲街弑〆低调 提交于 2021-02-16 20:30:17
问题 Here is a sample string: {three / fifteen / one hundred} this is the first random number, and this is the second, {two / four} From the brackets, I need to return a random value for example: One hundred is the first random number, and this is the second, two My code: function RandElement($str) { preg_match_all('/{([^}]+)}/', $str, $matches); return print_r($matches[0]); } $str = "{three/fifteen/one hundred} this is the first random number, and this is the second, {two/four}"; RandElement($str

C# Regex “Verbose” like in Python

对着背影说爱祢 提交于 2021-02-16 20:28:12
问题 In Python, we have the re.VERBOSE argument that allows us to nicely format regex expressions and include comments, such as import re ric_index = re.compile(r'''( ^(?P<delim>\.) # delimiter "." (?P<root>\w+)$ # Root Symbol, at least 1 character )''',re.VERBOSE) Is there something similar in C#? 回答1: You can use verbatim string (using @ ), which allow you to write: var regex = new Regex(@"^(?<delim>\\.) # delimiter ""."" (?<root>\\w+)$ # Root Symbol, at least 1 character ", RegexOptions

JavaScript Regex Infinite Loop on Some Patterns

。_饼干妹妹 提交于 2021-02-16 20:18:15
问题 I am trying to use the exec method on the JavaScript Regex object and can get into an infinite loop where exec does not return a null depending on the expression. Here is a test function I wrote to illustrate the problem. I ran it in Chrome 32. I am defining the Regex and match variables outside the loop. The max / Reached Max test is there to break out of the infinite loop. function textExec(reg, text, max) { max = max || 10 var match = null; while (match = reg.exec(text)) { console.log

Regexp “does not contain attribute” in html

浪尽此生 提交于 2021-02-16 20:10:53
问题 I'm looking for a simple regular expression (I think), that would return all html tags not having a "name" attribute, but my weak regexp skills won't help me much. Finding a html tag is not a problem, but the "which does not contain" is. I simply have no idea (well I had, but none of them work). Any clue? 回答1: First of all, you should not use regex for this task. An HTML parser surely exists in whatever language you are using and is way better suited for this. Now, if you need to use regex

Split file by vector of line numbers

爱⌒轻易说出口 提交于 2021-02-16 20:10:35
问题 I have a large file, about 10GB. I have a vector of line numbers which I would like to use to split the file. Ideally I would like to accomplish this using command-line utilities. As a regex: File: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Vector of line numbers: 2 5 Desired output: File 1: 1 2 3 File 2: 4 5 6 7 8 9 10 11 12 File 3: 13 14 15 16 17 18 回答1: This might work for you: csplit -z file 2 5 or if you want regexp: csplit -z file /2/ /5/ With the default values, the output files will

Regex for Hebrew and symbols

馋奶兔 提交于 2021-02-16 20:07:10
问题 I need an expression that can accept only Hebrew letters and at least one space char. I tried this for Hebrew letters, but it doesn't match sentences with Hebrew text and spaces: result = Regex.IsMatch(txtName.Text, @"[\u05D0\u05D1\u05D2\u05D3\u05D4\u05D5\u05D6\u05D7\u05D8\u05D9\u05DA\u05DB\u05DC\u05DD\u05DE\u05DF\u05E0\u05E1\u05E2\u05E3\u05E4\u05E5\u05E6\u05E7\u05E8\u05E9\u05EA]"); How can I represent all the Hebrew letters and at least one space char in regEx? 回答1: You are looking for

RegEx only one dot inside string not at beginning or end

帅比萌擦擦* 提交于 2021-02-16 19:43:51
问题 How can I write a regular expression in javascript that only allows users to write this: abc.def , abc-def or abc So basically match a pattern that only contains letters (only lowercase [a-z]) and a . or - . But does not match - or . at the beginning or end of string or multiple times(only one . or - per string) So not allowing them to do: ..... abc...abc abc.abc.... abc----.... ...abc.abc .abc -abc etc. 回答1: Regex would be: /^[a-z]+([\.\-]?[a-z]+)?$/ JavaScript: var text = 'abc.def'; var

Parsing polynomial coefficients from string

*爱你&永不变心* 提交于 2021-02-16 19:43:05
问题 I'm trying to build a RegEx to parse the coefficients of a polynomial from a string. I thought I'd found a solution until I found one particular example, which I suspect is badly formatted, that broke my RegEx. I'm also not sure my solution is the most elegant. Here are some examples of the strings I need to parse: polys = ['1x', '3.8546E-27x^4-2.4333E-20x^3+5.1165E-14x^2+3.7718E-6x-6.1561E-1', '6.13159E-3x+0.348', '0.0100708x-40', '6.103516E-3x', '1E-6x', '1.4846859E-6x', '2435', '2.7883E

Regex - How to remove strings inside brackets?

依然范特西╮ 提交于 2021-02-16 19:04:44
问题 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 \(.*