正则表达式 - 替换字符串周围的包装

时间:2016-03-17 03:35:08

标签: regex string search replace wrapper

什么是可以解决这个问题的正则表达式:

{{ Form::label('events', 'Events') }}

进入这个:

<label for="events">Events</label>

我需要字符串&#34;事件&#34;和&#34;活动&#34;保持战略。

2 个答案:

答案 0 :(得分:3)

试试这个:

confirm("I am ready to play!");
var age = prompt("What's your age");
if(age > 13) {
  console.log( "We arent responsible if under age restriction");
} else {
  console.log("Enjoy!");
}

DEMO

答案 1 :(得分:1)

这也适用于您的样本,使用sed:

进行格式化
from collections import defaultdict

ratings= {
    'Shane': {'127 Hours': 5.0, 'Avatar': 4.5},
    'Jaycee': {'127 Hours': 4.8, 'Avatar': 3.5, 'Mad Max: Fury Road': 4.9}
}

# this creates a dictionary that sets a default value of an empty list on 
# access, which makes the aggregation a bit nicer since no 
# initialization is needed
by_movie = defaultdict(list)

# aggregate to the default dict
for name, mrs in ratings.items():
    for movie, rating in mrs.items():
        by_movie[movie].append(rating)

# calculate averages
averages = {movie: sum(movie_ratings) / len(movie_ratings) for movie, movie_ratings in by_movie.items()}

print averages

如果你想要它分为两部分:

sed -E "s#[^']+'([^']+)', '([^']+)'.*#<label for=\"\1\">\2</label>#"