我在堆栈溢出时看了几个线程,我找不到答案.我有一个像下面这样的xml文件设置:
<entry id="1" type="a">
<name>string 1</name>
<description>any description</description>
</entry>
<entry id="2" type="b">
<name>string 2</name>
<description>any description #2</description>
</entry>
Run Code Online (Sandbox Code Playgroud)
我需要选择所有"条目"标签并返回条目的ID,类型,内部名称和描述标签.我怎么能用C#这样做?
谢谢,
我对正则表达式很新,我需要一些帮助.我试着弄清楚自己,但没有运气!
我试图在2个字符串之间选择文本(最后一个字符串的字符)
即:
word word2 :
Run Code Online (Sandbox Code Playgroud)
我想在word和之间选择"word2":
谢谢!
我在main.cpp的另一个.h和.cpp文件中有一个类.
在main.cpp中:
#include <iostream>
#include "filestuff.h"
#include "stream.h" <-- right here
int main(int argc, char** args)
{
if(!args[1])
return 0;
u64 filesize = 0;
get_file_size(args[1], &filesize);
u8* fd = new u8[filesize];
read_file(args[1], fd, filesize);
Stream s = new Stream(fd, filesize, "rb", BigEndian );
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在Stream.h中
#include <iostream> //just in case?
#if defined(_WIN32) && defined(_MSC_VER)
typedef __int64 s64;
typedef unsigned __int64 u64;
#else
typedef long long int s64;
typedef unsigned long long int u64;
#endif
typedef unsigned long …Run Code Online (Sandbox Code Playgroud) 我一直在研究这个,只发现了2个相关的答案,但仍然没有完全奏效.
无论如何.我正在尝试在文本中找到链接并自动链接它们,如果它们已经在html标记中,则不会自动链接它们.(<a> <img>)并且它必须支持所有链接,如http,https和www
我对正则表达式很可怕,但我试图把东西放在一起.
function b($text)
{
// a more readably-formatted version of the pattern is on http://daringfireball.net/2010/07/improved_regex_for_matching_urls
$pattern = '(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))';
$callback = create_function('$matches', '
$url = array_shift($matches);
$url_parts = parse_url($url);
$text = parse_url($url, PHP_URL_HOST) . parse_url($url, PHP_URL_PATH);
$text = preg_replace("/^www./", "", $text);
$last = -(strlen(strrchr($text, "/"))) + 1;
if ($last < 0) {
$text = substr($text, 0, $last) . "…";
}
return "<a rel="nofollow" href=".$url.">".$text."</a>";
');
return preg_replace_callback($pattern, $callback, $text);
}
function autolink($txt)
{
return preg_replace_callback('#(?<!href\=[\'"])(https?|ftp|file)://[-A-Za-z0-9+&@\#/%()?=~_|$!:,.;]*[-A-Za-z0-9+&@\#/%()=~_|$]#', 'b', $txt);
} …Run Code Online (Sandbox Code Playgroud) 我知道如何在PHP中执行此操作,但我需要在javascript/jquery中完成此操作.
我正在尝试以下内容:
$('#NewBox').html( $('#OldBox').html().Replace('/<img(.*)alt="(.*)"\>/g', "$2") );
Run Code Online (Sandbox Code Playgroud)
我不认为javascript有preg_replace,我所知道的是替换方法.使用"g"应该用正则表达式中的第二个参数替换所有实例(是alt).知道为什么这不起作用吗?
更新:(希望这更好地了解我想要的)
我有一个这样的字符串:
var str = 'This is a string with <img src="./images/logo.png" alt="logo" /> an image'
Run Code Online (Sandbox Code Playgroud)
我想用alt替换该字符串中的所有标签,所以它现在是:
'This is a string with logo an image'
Run Code Online (Sandbox Code Playgroud) 对于这样一个noobie问题很抱歉,我以前从未遇到过这个问题,我在线查看但只能找到argc和argv的描述.
无论如何,我在visual studio 2012中启动了一个新的win32控制台项目.我点击了空项目,然后开始添加program.cpp,其内容如下:
#include <iostream>
#include <Windows.h>
int main(int argc, char** argv)
{
printf( "%d", argc );
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我打算使用参数来创建一个程序,这就是为什么我需要argc才能正常工作.关于输出大量数字的代码,如'21374903'.在属性 - >链接器 - >高级我将入口点设置为'main'.
有什么我做错了吗?我可以添加设置以使其正常工作吗?
按位运算符非常有趣所以我试图找出一种方法来产生相反的效果,或者不是xor的效果.
如果我有两个字符(8位):
char1 char2
===== =====
1010 1000
after transformation
1000 1000
Run Code Online (Sandbox Code Playgroud)
如果0010是我要将char1和char2转移到该注册商处禁用的值(位置1)
我该怎么办?
or如果为1和1,则仅设置1,并且xor仅在1和0或0和1时交换值
我有这个巨大的问题,我不知道如何解决.我有一个重定向到网址的脚本.
到目前为止,我有:
//do some mysql
$geo_included = true; //trying to fix infinite redirect loop.
if($geo_included === true){
header('Location: '.$url["url"]); //this is causing the issue with redirect loop
}
Run Code Online (Sandbox Code Playgroud)
例如,$ url ["url"]是:www.google.com
但是,当我转到该PHP文件时,它将重定向到:
www.sitename.com/www.google.com
Run Code Online (Sandbox Code Playgroud)
并说有一个无限的重定向循环.注意:上面的标题位置脚本不在while/for/foreach循环中.
这是/目录的.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?group=$1 [L]
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?