English 中文(简体)
Regex:对H1十字路口的殖民后对等?
原标题:Regex: match after colon in H1 tag?
  • 时间:2012-04-16 21:15:05
  •  标签:
  • regex

我希望我能问这个问题,我就在四舍五入周围搜寻,找到了简单的问题,但没有为我找到解决办法。

I have HTML like this: <h1>Beatles: A Hard Days Night</h1> now I would like a regex to match everything AFTER the colon. So A Hard Days Night in this case.

这是我尝试的:

$pattern = "/<h1>:(.*)</h1>/";

但是,这只是空洞的。

最佳回答

The following regex should amount that:

<h1>[^:]+:s+([^<]+)

权力 壳牌测试:

PS>  <h1>Beatles: A Hard Days Night</h1>  -match  <h1>[^:]+:s+([^<]+) ; $Matches
True

Name                           Value
----                           -----
1                              A Hard Days Night
0                              <h1>Beatles: A Hard Days Night

没有什么解释:

<h1>    # match literal <h1>
[^:]+   # match everything *before* the colon (which in this case
        # shouldn t include a colon itself; if it does, then use .*)
:       # Literal colon
s+     # Arbitrary amount of whitespace
([^<]+) # Put everything up to the next < into a capturing group.
问题回答

暂无回答




相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签