我有一个多行文本,我想从这里匹配文字之间的“描述量”和一个随机数字,逗号作为分隔符。
示例输入:
Description Amount
Being the Amount received from above branch in favour of SAF SAF
FOR THE MONTH OF JANUARY-2021.
3,24,500.00
预期输出:
Being the Amount received from above branch in favour of SAF SAF
FOR THE MONTH OF JANUARY-2021.
示例输入:
Description Amou
select regexp_replace(
E'In most cases regexp_matches() should be used with the g flag,' ||
E'since if you only want\n the first match, it''s easier and more efficient'||
E'to use regexp_match(). \nHowever, regexp_match() only exists in '||
E'PostgreSQL version 10
我有下面的绳子。该字符串具有三个用户的数据(@ID:username__FULLNAME)。我想把它们挖出来。我尝试了下面的代码,但没有得到想要的结果。
ID is integer type
username and FULLNAME may contain numbers, letter and all kind of special chars.
$t = 'Hi @[4232:mark__MΛRK ATTLEY] how are you ?
Hi @[4232:ryan__RYΛN вυηту] how are you ?
Hi @[4232:david_
当我运行以下代码时:
导入re
s = 'baaaad'
l = re.findall(r'((a)(?=a))', s)
print l
for elem in l:
print ''.join(elem)
我得到了输出:
('a','a'),('a','a'),('a','a') aa aa
和预期的一样。但是,当我尝试相应的查找策略时,例如:
s = 'baaaad'
l = re.findall(r'((?&
下面的代码从HTML和PHP文件中删除了注释、换行符和额外的空格,但我遇到的一个问题是,原始文件中包含<<<EOT;。我应该使用什么正则表达式规则在$pre6的<<<EOT;之前和之后添加换行符
//a bit messy, but this is the core of the program. removes whitespaces, line breaks, and comments. sometimes makes EOT error.
$pre1 = preg_replace('#<!--[^\[<>].*?(?<!
我使用C中的POSIX正则表达式regex.h来计算一个短语在英语文本片段中出现的次数。但是,的返回值仅显示是否找到匹配项。因此,我尝试使用nmatch和matchptr来寻找不同的外观,但是当我从matchptr打印匹配时,我只收到了第一个短语的索引出现在我的文本中。
这是我的代码:
#include <sys/types.h>
#include <regex.h>
#include <stdio.h>
#define MAX_MATCHES 20 //The maximum number of matches allowed in a single s
对使用分组和拆分操作是否有一些警告?
在perl中:
print join("|",split(m/(A|AND)/,"foo A bar"))."\n";
预期:
foo | bar
输出:
foo |A| bar
Powershell的相同预期/输出:
([regex]::Split("foo A bar","(A|AND)"))-join"|"
似乎在使用分组时出现了问题--没有括号,一切都很好:
([regex]::Split("foo A bar","A|B"
我正在尝试编写一个可以包含几个scenarious的正则表达式。主要有以下几点:
node 'test1000.sov.local' {
include AV::AB
}
或
node 'test1000.sov.local' {
include ZY::ZT::ZZ
include AV::AB
}
或
node 'test1000.sov.local' {
include ZY::ZT::ZZ
include preinstall::global
include AV::AB
}
从理论上讲,它可以是节点下的任意数量的include
这是我试
我有下面的字符串,现在如果它包含Continue? [Y/N],我想匹配它。我尝试了几种方法,但没有像预期的那样起作用。如果包含Continue? [Y/N],则任何与完整字符串匹配的建议
输入字符串:
Warning: do you want to proceed, some-more,text. Continue? [Y/N]
我正在用perl编写一个正则表达式,以匹配启动Perl子例程定义的perl代码。下面是我的正则表达式:
my $regex = '\s*sub\s+([a-zA-Z_]\w*)(\s*#.*\n)*\s*\{';
$regex匹配启动子例程的代码。我还试图以$1为单位捕获子例程的名称,以及以$2为单位的子例程名称和初始左括号之间的空格和注释,因为$2给了我一个问题。
考虑以下perl代码:
my $x = 1;
sub zz
# This is comment 1.
# This is comment 2.
# This is comment 3.
{
$x = 2;
最近,我一直在使用Python中的regex表达式,在r"(\w{3})+"和它的非贪婪的等价r"(\w{3})+?"中遇到了一个问题。请让我们看看下面的示例:
S = "abcdefghi" # string used for all the cases below
1.贪婪搜索
m = re.search(r"(\w{3})+", S)
print m.group() # abcdefghi
print m.groups() # ('ghi',)
m.group和我预期的完全一样--只是整场比赛而已。
我一直试图为我的女儿写一款超现实的文字冒险游戏,一切都进行得很顺利,但我不得不尝试用RegEx处理一个特定的输入。
输入字符串需要以数字(可选小数)开头,后面跟着一系列字符(最小1,最大n),紧接着是空格,然后是或,然后是空格,然后是n个单词(没有数字),直到拆分单词(和)。“和”之后的任何单词也需要在另一组中捕获。
因此,一个有效的输入示例可能是:
5 blue cows and a bucket of milk
或
2.5mph and a really slow car
然后分成三组,如下:
[5] [blue cows] [a bucket of milk] or [2.5] [mph
我有一条包含大量\n和|的文本。以下是一个示例:
this is a sample\n text. This symbol | shows what I am talking about.
This is \n another | sample
我希望能够提取\n和|之间的所有内容。对于上面的例子,这是:text. This symbol和another,我如何在Python2.7中做到这一点?
使用angularjs的api代码。对这个功能感兴趣。不理解它是如何得到多个匹配的。例如,在语句中,是使用args、和arg。
var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
function anonFn(fn) {
// For anonymous functions, showing at the very least the function signature can help in
// debuggin
投入:-
x = 'William John <William.John@InfoTechservices.com>; C S N Murphy <CSN.Murphy@InfoTechservices.com>; Raja Rahim<Rahim.Raja@InfoTechservices.com>'
预期产出:-
y = ['William John','C S N Murphy','Raja Rahim']
失败的审判:-
Input- re.findall(r"; (.*?)&l
我只想打印匹配的线和剥离无与伦比的,但与以下:
$ echo test12 test | sed -n 's/^.*12/**/p'
我总是得到:
** test
而不是:
**
我做错了什么?
edit1
我提供了更多的信息,我需要什么-实际上,我应该从它开始。因此,我有一个命令,它产生了大量的输出行,我只想获取行的一部分--匹配的行,并去掉结果。因此,在上面的示例中,12的目的是查找行中匹配部分的末尾,而不是**,我应该将其放到&它表示匹配的字符串。因此,完整的例子是:
echo test12 test | sed -n 's/^.*12/&/p