regex

Whole word regex matching and hyperlinking in Javascript

陌路散爱 提交于 2021-02-04 08:09:51
问题 I need a little help with Regular Expressions. I'm using Javascript and JQuery to hyperlink terms within an HTML document, to do this I'm using the following code. I'm doing this for a number of terms in a massive document. var searchterm = "Water"; jQuery('#content p').each(function() { var content = jQuery(this), txt = content.html(), found = content.find(searchterm).length, regex = new RegExp('(' + searchterm + ')(?![^(<a.*?>).]*?<\/a>)','gi'); if (found != -1) { //hyperlink the search

Email validation- characters length before @ and before dot

六眼飞鱼酱① 提交于 2021-02-04 07:53:07
问题 I use the following regex pattern for validating the email address that works fine, BUT I need to validate the length of characters before @ , which should NOT be less than 4 characters. The same rule I should put for the length of characters after @ and before dot . . For example, this email address is NOT valid: a@b.c However, this one should be valid: abcd@abcd.com How can I do it? Here is my current attempt: <ui:define name="validation-tag"> <f:validateRegex pattern="([\w\.-]*[a-zA-Z0-9_]

Regular Expression check length

无人久伴 提交于 2021-02-04 07:47:11
问题 I have been trying to make a regular expression for my mobile phones but I can't seem to get it to work: Here are the conditions for my regular expression: must start with 09 total length is 9 Here is my regular expression: [0]{1}[9]{1}[0-9]{7} Valid mobile number 091123456 Invalid mobile number 0991234567 || 09912345 回答1: Easiest way: ^09[0-9]{7}$ Explanation: ^09 => begins by 09 [0-9] => any character between 0 and 9 {7} exactly seven times $ => Ends with the latest group ([0-9]{7}) 回答2: If

What causes Python error 'bad escape \C'?

浪尽此生 提交于 2021-02-04 07:35:26
问题 I just wrote a function that will look at a text file and count all of the instances of True and False in the text file. Here is my file ATOM 43 CA LYS A 5 14.038 15.691 37.608 1.00 15.15 C True ATOM 52 CA CYS A 6 16.184 12.782 38.807 1.00 16.72 C True ATOM 58 CA GLU A 7 17.496 12.053 35.319 1.00 14.06 C False ATOM 67 CA VAL A 8 18.375 15.721 34.871 1.00 12.27 C True ATOM 74 CA PHE A 9 20.066 15.836 38.288 1.00 12.13 C False ATOM 85 CA GLN A 10 22.355 12.978 37.249 1.00 12.54 C False And here

C# 词法分析器(七)总结

落爺英雄遲暮 提交于 2021-02-04 07:27:32
系列导航 (一)词法分析介绍 (二)输入缓冲和代码定位 (三)正则表达式 (四)构造 NFA (五)转换 DFA (六)构造词法分析器 (七)总结 在之前的六篇文章中,我比较详细的介绍了与词法分析器相关的算法。它们都比较关注于实现的细节,感觉上可能比较凌乱,本篇就从整体上介绍一下如何定义词法分析器,以及如何实现自己的词法分析器。 第二节完整的介绍了如何定义词法分析器,可以当作一个词法分析器使用指南。如果不关心词法分析器的具体实现的话,可以只看第二节。 一、类库的改变 首先需要说明一下我对类库做的一些修改。词法分析部分的接口,与当初写《C# 词法分析器》系列时相比,已经发生了不小的改变,有必要做一下说明。 1. 词法单元的标识符 词法单元(token)最初的定义是一个 Token 结构,使用一个 int 属性作为词法单元的标识符,这也是很多词法分析器的通用做法。 但后来做语法分析的时候,感觉这样非常不方便。因为目前还不支持从定义文件生成词法分析器代码,只能在程序里面定义词法分析器。而 int 本身是不具有语义的,作为词法单元的标识符来使用,不但不方便还容易出错。 后来尝试过使用字符串作为标识符,虽然解决了语义的问题,但仍然容易出错,实现上也会复杂些(需要保存字符串字典)。 而既简单,又具有语义的解决方案,就是使用枚举了。枚举名称提供了语义,枚举值又可以转换为整数

The best way to match at least three out of four regex requirements

喜欢而已 提交于 2021-02-04 07:12:55
问题 In password strategy, there are 4 requirements. It should contains any three of the following lower case. upper case. numeric. special character. The following regex will match all cases ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).{4,8}$ I know I can use '|' to declare all combinations, however, that will produce a supper long regex. What is the best way to replace '|' so that it can check if the input contains any of three conditions in the combination? 回答1: If you're using a PCRE

The best way to match at least three out of four regex requirements

大憨熊 提交于 2021-02-04 07:12:51
问题 In password strategy, there are 4 requirements. It should contains any three of the following lower case. upper case. numeric. special character. The following regex will match all cases ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).{4,8}$ I know I can use '|' to declare all combinations, however, that will produce a supper long regex. What is the best way to replace '|' so that it can check if the input contains any of three conditions in the combination? 回答1: If you're using a PCRE

Regex with prefix and optional suffix

折月煮酒 提交于 2021-02-04 06:19:47
问题 This is maybe the 100+1 question regarding regex optional suffixes on SO, but I didn't find any, that could help me :( I need to extract a part of string from the common pattern: prefix/s/o/m/e/t/h/i/n/g/suffix using a regular expression. The prefix is constant and the suffix may not appear at all, so prefix/(.+)/suffix doesn't meet my requirements. Pattern prefix/(.+)(?:/suffix)? returns s/o/m/e/t/h/i/n/g/suffix . The part (?:/suffix)? must be somehow more greedy. I want to get s/o/m/e/t/h/i

Regex with prefix and optional suffix

若如初见. 提交于 2021-02-04 06:18:25
问题 This is maybe the 100+1 question regarding regex optional suffixes on SO, but I didn't find any, that could help me :( I need to extract a part of string from the common pattern: prefix/s/o/m/e/t/h/i/n/g/suffix using a regular expression. The prefix is constant and the suffix may not appear at all, so prefix/(.+)/suffix doesn't meet my requirements. Pattern prefix/(.+)(?:/suffix)? returns s/o/m/e/t/h/i/n/g/suffix . The part (?:/suffix)? must be somehow more greedy. I want to get s/o/m/e/t/h/i

pandas.replace conflict with str.replace regex. Code Order

邮差的信 提交于 2021-02-02 09:55:32
问题 My task is to remove any content in a parenthesis and remove any numbers followed by Country name. Change the names of a couple of countries. e.g. Bolivia (Plurinational State of)' should be 'Bolivia' Switzerland17' should be 'Switzerland'`. My original code was in the order: dict1 = { "Republic of Korea": "South Korea", "United States of America": "United States", "United Kingdom of Great Britain and Northern Ireland": "United Kingdom", "China, Hong Kong Special Administrative Region": "Hong