Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 此函数的正则表达式模式_Regex - Fatal编程技术网

Regex 此函数的正则表达式模式

Regex 此函数的正则表达式模式,regex,Regex,例如: 目前我正在使用下面的正则表达式来替换DNS名称 “^((?:http?:(?:\/\/)?)?)[^\/]*” 它工作正常,但它正在用其他字符串替换“”,但我只想替换域名,而目录信息应保持原样 i、 e.abc.xyz.com,其他字符串不是http:// 例: 字符串re=“/^(?(?!https?:\/\/\/\/)+/gm”; 字符串str=“” System.out.println(str.replace(re,subst)) 实际:“” 预期:“” o/p不工作 有人能帮我吗

例如:

目前我正在使用下面的正则表达式来替换DNS名称 “^((?:http?:(?:\/\/)?)?)[^\/]*”

它工作正常,但它正在用其他字符串替换“”,但我只想替换域名,而目录信息应保持原样

i、 e.abc.xyz.com,其他字符串不是http://

例:

字符串re=“/^(?(?!https?:\/\/\/\/)+/gm”; 字符串str=“”

System.out.println(str.replace(re,subst))

实际:“” 预期:“”

o/p不工作

有人能帮我吗

String subst = "www.xyz.com";
您可以试试这个。替换为
www.xyz.com
。请参阅演示

尝试一下:

搜索:
(https?:/)?\w+(.*)


并替换为:
$1www$2

基本上,您只希望所有内容都达到第一个正斜杠?我假设您不能使用您语言中的任何文字替换函数将“abc.xyz.com”替换为“www.xyz.com”?(例如,
str_replace(“abc.xyz.com”,“www.xyz.com”,“$subject”)
)感谢您的回复,但缺少一个标准,即url以“http”开头。我试过了,它不起作用。我正在对此URL应用相同的模式,但它不起作用。请帮助我获取精确的正则表达式。提前感谢
{crea}&secure\u id=[secure\u id]&position={heigherposition}&search\u device={network}&device={device}&match\u type={matchtype}
应替换为www.trails.com
请帮助我找出正确的模式字符串s=“{crea}&secure\u id=[secure\u id]&position={heigherposition}&search\u device={network}&device={device}&match\u type={matchtype}”;字符串smRegexSt=“^([^\“]*\”(?:http?:(?:\/\\/)?)?)[^\/]*”;Pattern smExtRegex=Pattern.compile(smRegexSt);Matcher Matcher=smExtRegex.Matcher;字符串url=null;if(matcher.find()){url=matcher.replaceAll(“www.trails.com”);}System.out.println(url);我使用上述代码,但它是打印值为“空”感谢现在它的工作。但最后一个帮助要求我有相同模式的不同网址,但我只想替换我在下面添加的网址。你能看一下,让我知道这一个也不工作。你能看一下上面的要求一次吗?
String subst = "www.xyz.com";
^(?:(?!https?:\/\/|\/).)+
var re = /^(?:(?!https?:\/\/|\/).)+/gm;
var str = 'abc.xyz.com/name=test&account=google&search=google"\nhttp://abc.xyz.com/name=test&account=google&search=google"\nhttps://abc.xyz.com/name=test&account=google&search=google"\ntextile.trails.com/…{crea}&secure‌​_id=[SECURE_ID]&position={heigherposition}&search_device={network}&device={device‌​}&match_type={matchtype}';
var subst = 'www.xyz.com';

var result = str.replace(re, subst);