regex

JavaScript regular expression to replace a sequence of chars

喜夏-厌秋 提交于 2021-02-10 08:42:06
问题 I want to replace all spaces in the beginning and the end of a string with a underscore in this specific situation: var a = ' ## ## # '; console.log(myReplace(a)); // prints ___## ## #__ i.e.: all the spaces in the beginning of the string before the first # and all the spaces after the last #, everything else (including spaces in the middle of the string) remains untouched. My initial thinking was to use two Reg Exp, one for each part of the problem. However, I couldn't get the first one and

Only extract those words from a list that include no repeating letters, using regex

丶灬走出姿态 提交于 2021-02-10 08:41:52
问题 I have a large word list file with one word per line. I would like to filter out the words with repeating alphabets. INPUT: abducts abe abeam abel abele OUTPUT: abducts abe abel I'd like to do this using Regex (grep or perl or python). Is that possible? 回答1: It's much easier to write a regex that matches words that do have repeating letters, and then negate the match: my @input = qw(abducts abe abeam abel abele); my @output = grep { not /(\w).*\1/ } @input; (This code assumes that @input

PHP Regex: Matching Ands - & and &

别等时光非礼了梦想. 提交于 2021-02-10 08:10:14
问题 I am trying to matching and characters from html. There are three types of ands: and, &, & I'm using the following code: (&|&|\band\b) The problem with above code is: it also matches words which start with & i.e. © € I've also tried the following, but it does not match & character from the start and end of line in the text. (\s&\s|&|\band\b) 回答1: How about (&)|&(?!\w)|\band\b Matches and , & , & Does not match © € The middle one matches an ampersand that is not followed by a word character (

PHP Regex: Matching Ands - & and &

回眸只為那壹抹淺笑 提交于 2021-02-10 08:06:41
问题 I am trying to matching and characters from html. There are three types of ands: and, &, & I'm using the following code: (&|&|\band\b) The problem with above code is: it also matches words which start with & i.e. © € I've also tried the following, but it does not match & character from the start and end of line in the text. (\s&\s|&|\band\b) 回答1: How about (&)|&(?!\w)|\band\b Matches and , & , & Does not match © € The middle one matches an ampersand that is not followed by a word character (

PHP Regex: Matching Ands - & and &

倾然丶 夕夏残阳落幕 提交于 2021-02-10 08:05:10
问题 I am trying to matching and characters from html. There are three types of ands: and, &, & I'm using the following code: (&|&|\band\b) The problem with above code is: it also matches words which start with & i.e. © € I've also tried the following, but it does not match & character from the start and end of line in the text. (\s&\s|&|\band\b) 回答1: How about (&)|&(?!\w)|\band\b Matches and , & , & Does not match © € The middle one matches an ampersand that is not followed by a word character (

C# 爬虫

ぐ巨炮叔叔 提交于 2021-02-10 07:38:29
//PS 需要引用HtmlAgilityPack.dll 文件,可自行在网上下载 public partial class GrabInterface : Form { public int number = 1; public GrabInterface() { InitializeComponent(); this.Load += GrabInterface_Load; } //定时器 System.Timers.Timer myTimer; //定义委托,防止两线程之间控件赋值冲突 public delegate void Action<in T>(T obj); public void ActionRead(int t) { this.lbl_ok.Text = "正在读取中,请稍后..."; this.btn_sure.Enabled = false; } public void ActionFinall(int t) { this.lbl_ok.Text = "读取完毕"; this.btn_sure.Enabled = false; } public static bool result = true;//设置定时器点击按钮时执行,避免重复执行定时器导致时间混乱 private void btn_sure_Click(object sender, EventArgs

How to ignore spaces only for dynamic content while forming an regular expression to compare two sentences?

若如初见. 提交于 2021-02-10 07:34:20
问题 I have a sentence, and I need to compare it with customer send message and return whether it has been passed or failed. Sentence contains {#val#}, which can be replaced by any values in the customer send messages. Condition here is in place of {#val#} in a sentence => Customer message can contain anything within the limit of 5. {#val#} is the dynamic content. Other part of the messages are static content. In static content of the customer message, we can ignore the space and compare with the

How to ignore spaces only for dynamic content while forming an regular expression to compare two sentences?

十年热恋 提交于 2021-02-10 07:33:54
问题 I have a sentence, and I need to compare it with customer send message and return whether it has been passed or failed. Sentence contains {#val#}, which can be replaced by any values in the customer send messages. Condition here is in place of {#val#} in a sentence => Customer message can contain anything within the limit of 5. {#val#} is the dynamic content. Other part of the messages are static content. In static content of the customer message, we can ignore the space and compare with the

Regex for matching a tag in a Liquid template : “>” inside html tag

寵の児 提交于 2021-02-10 06:49:07
问题 I have to write a match pattern for the body tag in a Liquid template. While matching HTML tags is pretty straightforward, I have the problem that HTML special character can be used inside the Liquid code. Example: <body class="template-{{ template | replace: '.', ' ' | truncatewords: 1, '' }}{% if promo %}has-promo{% endif %} {% if products.size > 1 %}has-related-products{% endif %} {% if settings.product-hover == 'quick-shop' %}has-quick-shop{% endif %} loading" > or simplified: <body {%

Splitting a string using a JavaScript regex but keeping the delimiter?

核能气质少年 提交于 2021-02-10 06:45:06
问题 I'm receiving input like: F12T213B1239T2F13T341F324 and I have to group it by letter followed by the numbers that follows it. So the ideal output would be: F12,T213,B1239,T2,F13,T341,F324 And then do some processing on the numbers based on the letter that they're with. The letters are fixed, they are always B,F,T So far, I've tried to split it by letter with: var separators = ['T', 'B', 'F']; var parts = input.split(new RegExp('('+separators.join('|')+')'),'g'); But the problem with this is