user1514904
user1514904

Reputation: 23

Regular expression with brackets

How to get 'text' from this string:

{L[text]}

?

I tried

\{L\[*\]\}

but it doesnt work.

Upvotes: 1

Views: 91

Answers (3)

karllindmark
karllindmark

Reputation: 6071

Have you tried the following expression?

/\{L\[([^\]]*)\]\}/

Upvotes: 1

Alberto De Caro
Alberto De Caro

Reputation: 5213

The allowed characters class is missing:

\{L\[(\w*)\]\}

Where \w = [a-zA-Z0-9]. Required text is in group 1.

Demo

Upvotes: 3

Rawkode
Rawkode

Reputation: 22592

<?php
$s = "{L[hello you]}";
preg_match('/\{L\[(.*)\]\}/', $s, $matches);
print_r($matches);

Upvotes: 0

Related Questions