-3

我有以下字符串:

Str="   $str='The requirements of this chapter apply to the following:
              (a) New buildings or portions thereof used as health care occupancies (see 1.4.1) (b) Additions made to, or used as, a health care occupancy (see 4.6.6 and 18.1.1.4) Exception: The requirement of 18.1.1.1.1 shall not apply to additions classified as occupancies other than health care that are separated from the health care occupancy in accordance with 18.1.2.1(2) and conform to the requirements for the specific occupancy in accordance with Chapters 12 through 17 and Chapters 20 through 42, as appropriate. (c) Alterations, modernizations, or renovations of existing health care occupancies (see 4.6.7 and 18.1.1.4) (d) Existing buildings or portions thereof upon change of occupancy to a health care occupancy (see 4.6.11) Exception*: Facilities where the authority having jurisdiction has determined equivalent safety has been provided in accordance with Section 1.5.';
       ";

但我想要的输出是这样的:-

   $str='The requirements of this chapter apply to the following:
(a) New buildings or portions thereof used as health care occupancies (see 1.4.1) 

(b) Additions made to, or used as, a health care occupancy (see 4.6.6 and 18.1.1.4) Exception: The requirement of 18.1.1.1.1 shall not apply to additions classified as occupancies other than health care that are separated from the health care occupancy in accordance with 18.1.2.1(2) and conform to the requirements for the specific occupancy in accordance with Chapters 12 through 17 and Chapters 20 through 42, as appropriate.

 (c) Alterations, modernizations, or renovations of existing health care occupancies (see 4.6.7 and 18.1.1.4) 

(d) Existing buildings or portions thereof upon change of occupancy to a health care occupancy (see 4.6.11) Exception*: Facilities where the authority having jurisdiction has determined equivalent safety has been provided in accordance with Section 1.5.';

我想拆分条件(az)。如何使用正则表达式来做到这一点?

谢谢

4

3 回答 3

0

对于一组字符,您可以分别使用小写[a-z][A-Z]大写字母。您需要的不仅仅是字母,而是拆分(<letter>)(包括括号)。为此,您可能需要\([a-z]\)(即转义括号,因为它们是分隔表达式组的所谓元字符)。

于 2013-04-22T12:14:08.773 回答
0

你可以使用这个正则表达式:

 str = "The requirements of this chapter apply to the following:(a)hello (b)asdadsdsa (c)asdadssad";
 $str = str.replace(/(\([a-z]+\))/ig, "<br/>$1");
 /*
 $str's value now is:
 The requirements of this chapter apply to the following:
 <br/>(a)hello 
 <br/>(b)asdadsdsa 
 <br/>(c)asdadssad
 */
于 2013-04-22T12:23:23.887 回答
0

不完全确定你想要什么,但使用正则表达式替换应该让你开始:

$str.replace(/(\([a-z]+\))/ig, '\n$1');
于 2013-04-22T12:27:11.257 回答