使用 jQuery/PHP 删除通配符
嘿伙计们,我希望我能够尽可能简单地解释这一点。基本上我正在编译一个列表,为此我需要删除某个触发词后的大量文本。
假设我刚刚在文本中粘贴了一堆文本框,我希望除了第一个用户名之外的所有内容都被删除。
例子是...
流氓从 youaref0rsaken 转发了此
内容 youaref0rsaken 从 loveeoutoflust 转发了
此内容 loveeoutoflust 从 yourwatchfuleye 转发了此
内容 我想将其变成
流氓
youaref0rsaken
loveeoutoflust
使用带有输入的文本框、一个按钮和一个显示输出的文本框。我尝试使用 jquery 和 php preg_replace 执行此操作,但无法使其正常运行。
有人能帮我解决这个问题吗?
Hey guys, I hope I am able to explain this as easy as possible. Basically I am compiling a list and to do so I need to remove a load of text after a certain trigger word.
Example of what I am trying to achieve is here
Say I have just pasted a bunch of text in my text box, I want everything removed apart from the first username.
And example would be...
r-u-f-f-i-a-n reblogged this from youaref0rsaken
youaref0rsaken reblogged this from loveeoutoflust
loveeoutoflust reblogged this from yourwatchfuleye
Which I would want to turn in to
r-u-f-f-i-a-n
youaref0rsaken
loveeoutoflust
With using a textbox with the input, a button and a textbox which would display the output. I have tried doing this using jquery and php preg_replace but cannot get it to function correctly.
Is anyone able to help me with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
会给你结果
will give you as result
<罢工>
以 javascripts Replace funciton
为例,使用下面的代码查看此小提琴 http://jsfiddle.net/ vwhCx/
注意:如果正则表达式的概念对您来说是新的,那么这里唯一需要知道的是:/reblogged from/g 是//g 表示全球范围内,或多个匹配。
更新
根据您的评论
我已经更改了我的代码以在文本区域上工作使用这个
新的实时示例:http://jsfiddle.net/K3LZU/
LAST EDIT
如果您尝试将其显示为列表或换行符,请尝试 str.replace(/reblogged this from/g, ' \n') \n 表示换行符
look into javascripts replace funciton
as an example check out this fiddle using the code below http://jsfiddle.net/vwhCx/
note: if the concept of a regexp is new to you the only thing to know here: /reblogged this from/g is that the //g means globeably, or more than one match.
UPDATE
based on your comment I have altered my code to work on a text area
use this
new live example: http://jsfiddle.net/K3LZU/
LAST EDIT
if you are trying to display it as a list, or newlines try str.replace(/reblogged this from/g, '\n') the \n indicating a newline
如果它始终是第一个单词,您可以执行以下简单操作:
If it's always the first word, you can do something simple like this: