我已经在regex101上测试了我的正则表达式。
它运行完美,但是,在我的终端上,它不会“订阅” json文件。
我觉得这是由于在正则表达式中使用了单引号和双引号吗?因此,我将整个模式用三引号引起来。
JOIN
我希望子方法能够捕获唯一的组并将其替换为我的json文件。
答案 0 :(得分:1)
设计正则表达式来执行此任务可能不是最好的主意。
在这里,我们可能希望简化表达式以仅捕获第一个值。我对OAM不太确定,我想这不是必需的。然后,我们使用右边界在捕获组中捕获所需的姓氏,并使用左边界和右边界收集整个值,也许类似于:
: "(.+?(['A-za-z]+)\s(([A-Z]{2,3},\s)?[A-Z]{2}))"
# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r": \"(.+?(['A-za-z]+)\s(([A-Z]{2,3},\s)?[A-Z]{2}))\""
test_str = ("[\n"
"{\"name\": \"Hon Tony Abbott MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Anthony Albanese MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr John Alexander OAM, MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Dr Anne Aly MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Karen Andrews MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Kevin Andrews MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Adam Bandt MP\", \"party\": \"Australian Greens\"},\n"
"{\"name\": \"Ms Julia Banks MP\", \"party\": \"Independent\"},\n"
"{\"name\": \"Hon Sharon Bird MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Chris Bowen MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr Russell Broadbent MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Scott Buchholz MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Tony Burke MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Linda Burney MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Mark Butler MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Ms Terri Butler MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Anthony Byrne MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Dr Jim Chalmers MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr Nick Champion MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Darren Chester MP\", \"party\": \"The Nationals\"},\n"
"{\"name\": \"Ms Lisa Chesters MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr George Christensen MP\", \"party\": \"The Nationals\"},\n"
"{\"name\": \"Hon Jason Clare MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Ms Sharon Claydon MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon David Coleman MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Julie Collins MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr Pat Conroy MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Mark Coulton MP\", \"party\": \"The Nationals\"},\n"
"{\"name\": \"Mr Chris Crewther MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Milton Dick MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Mark Dreyfus QC, MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Damian Drum MP\", \"party\": \"The Nationals\"},\n"
"{\"name\": \"Hon Peter Dutton MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Justine Elliot MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Warren Entsch MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Trevor Evans MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Jason Falinski MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Joel Fitzgibbon MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Paul Fletcher MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Ms Nicolle Flint MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Dr Mike Freelander MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Josh Frydenberg MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Andrew Gee MP\", \"party\": \"The Nationals\"},\n"
"{\"name\": \"Mr Steve Georganas MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr Andrew Giles MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Dr David Gillespie MP\", \"party\": \"The Nationals\"},\n"
"{\"name\": \"Mr Ian Goodenough MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Patrick Gorman MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr Luke Gosling OAM, MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr Ross Hart MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr Andrew Hastie MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Alex Hawke MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Chris Hayes MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Sarah Henderson MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Julian Hill MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr Kevin Hogan MP\", \"party\": \"The Nationals\"},\n"
"{\"name\": \"Mr Luke Howarth MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Greg Hunt MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Ed Husic MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Steve Irons MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Stephen Jones MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Barnaby Joyce MP\", \"party\": \"The Nationals\"},\n"
"{\"name\": \"Hon Bob Katter MP\", \"party\": \"Katter's Australian Party\"},\n"
"{\"name\": \"Ms Ged Kearney MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Ms Justine Keay MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Michael Keenan MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Craig Kelly MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Dr Mike Kelly AM, MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr Matt Keogh MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr Peter Khalil MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Catherine King MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Ms Madeleine King MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Ms Susan Lamb MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr Andrew Laming MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Michelle Landry MP\", \"party\": \"The Nationals\"},\n"
"{\"name\": \"Mr Julian Leeser MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Dr Andrew Leigh MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Sussan Ley MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon David Littleproud MP\", \"party\": \"The Nationals\"},\n"
"{\"name\": \"Mrs Nola Marino MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Richard Marles MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Ms Emma McBride MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Michael McCormack MP\", \"party\": \"The Nationals\"},\n"
"{\"name\": \"Hon Dr John McVeigh MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Brian Mitchell MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr Rob Mitchell MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Scott Morrison MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Ben Morton MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Shayne Neumann MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr Llew O'Brien MP\", \"party\": \"The Nationals\"},\n"
"{\"name\": \"Mr Ted O'Brien MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Brendan O'Connor MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr Ken O'Dowd MP\", \"party\": \"The Nationals\"},\n"
"{\"name\": \"Hon Kelly O'Dwyer MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Ms Clare O'Neil MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Ms Cathy O'Toole MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Ms Julie Owens MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr Tony Pasin MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Graham Perrett MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Dr Kerryn Phelps AM, MP\", \"party\": \"Independent\"},\n"
"{\"name\": \"Hon Keith Pitt MP\", \"party\": \"The Nationals\"},\n"
"{\"name\": \"Hon Tanya Plibersek MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Christian Porter MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Melissa Price MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Christopher Pyne MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Rowan Ramsey MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Amanda Rishworth MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Stuart Robert MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Ms Michelle Rowland MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Ms Joanne Ryan MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Ms Rebekha Sharkie MP\", \"party\": \"Centre Alliance\"},\n"
"{\"name\": \"Hon Bill Shorten MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Tony Smith MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Warren Snowdon MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Ms Anne Stanley MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Michael Sukkar MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Ms Meryl Swanson MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Angus Taylor MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Dan Tehan MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Ms Susan Templeman MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Matt Thistlethwaite MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Hon Alan Tudge MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Ms Maria Vamvakinou MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr Bert van Manen MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Ross Vasta MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Andrew Wallace MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Tim Watts MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mrs Lucy Wicks MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Andrew Wilkie MP\", \"party\": \"Independent\"},\n"
"{\"name\": \"Mr Josh Wilson MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr Rick Wilson MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Tim Wilson MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Jason Wood MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Hon Ken Wyatt AM, MP\", \"party\": \"Liberal Party of Australia\"},\n"
"{\"name\": \"Mr Tony Zappia MP\", \"party\": \"Australian Labor Party\"},\n"
"{\"name\": \"Mr Trent Zimmerman MP\", \"party\": \"Liberal Party of Australia\"}\n"
"]")
subst = ": \"\\2\""
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 0, re.MULTILINE)
if result:
print (result)
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
const regex = /: \"(.+?(['A-za-z]+)\s(([A-Z]{2,3},\s)?[A-Z]{2}))\"/gm;
const str = `[
{"name": "Hon Tony Abbott MP", "party": "Liberal Party of Australia"},
{"name": "Hon Anthony Albanese MP", "party": "Australian Labor Party"},
{"name": "Mr John Alexander OAM, MP", "party": "Liberal Party of Australia"},
{"name": "Dr Anne Aly MP", "party": "Australian Labor Party"},
{"name": "Hon Karen Andrews MP", "party": "Liberal Party of Australia"},
{"name": "Hon Kevin Andrews MP", "party": "Liberal Party of Australia"},
{"name": "Mr Adam Bandt MP", "party": "Australian Greens"},
{"name": "Ms Julia Banks MP", "party": "Independent"},
{"name": "Hon Sharon Bird MP", "party": "Australian Labor Party"},
{"name": "Hon Chris Bowen MP", "party": "Australian Labor Party"},
{"name": "Mr Russell Broadbent MP", "party": "Liberal Party of Australia"},
{"name": "Hon Scott Buchholz MP", "party": "Liberal Party of Australia"},
{"name": "Hon Tony Burke MP", "party": "Australian Labor Party"},
{"name": "Hon Linda Burney MP", "party": "Australian Labor Party"},
{"name": "Hon Mark Butler MP", "party": "Australian Labor Party"},
{"name": "Ms Terri Butler MP", "party": "Australian Labor Party"},
{"name": "Hon Anthony Byrne MP", "party": "Australian Labor Party"},
{"name": "Dr Jim Chalmers MP", "party": "Australian Labor Party"},
{"name": "Mr Nick Champion MP", "party": "Australian Labor Party"},
{"name": "Hon Darren Chester MP", "party": "The Nationals"},
{"name": "Ms Lisa Chesters MP", "party": "Australian Labor Party"},
{"name": "Mr George Christensen MP", "party": "The Nationals"},
{"name": "Hon Jason Clare MP", "party": "Australian Labor Party"},
{"name": "Ms Sharon Claydon MP", "party": "Australian Labor Party"},
{"name": "Hon David Coleman MP", "party": "Liberal Party of Australia"},
{"name": "Hon Julie Collins MP", "party": "Australian Labor Party"},
{"name": "Mr Pat Conroy MP", "party": "Australian Labor Party"},
{"name": "Hon Mark Coulton MP", "party": "The Nationals"},
{"name": "Mr Chris Crewther MP", "party": "Liberal Party of Australia"},
{"name": "Mr Milton Dick MP", "party": "Australian Labor Party"},
{"name": "Hon Mark Dreyfus QC, MP", "party": "Australian Labor Party"},
{"name": "Hon Damian Drum MP", "party": "The Nationals"},
{"name": "Hon Peter Dutton MP", "party": "Liberal Party of Australia"},
{"name": "Hon Justine Elliot MP", "party": "Australian Labor Party"},
{"name": "Hon Warren Entsch MP", "party": "Liberal Party of Australia"},
{"name": "Mr Trevor Evans MP", "party": "Liberal Party of Australia"},
{"name": "Mr Jason Falinski MP", "party": "Liberal Party of Australia"},
{"name": "Hon Joel Fitzgibbon MP", "party": "Australian Labor Party"},
{"name": "Hon Paul Fletcher MP", "party": "Liberal Party of Australia"},
{"name": "Ms Nicolle Flint MP", "party": "Liberal Party of Australia"},
{"name": "Dr Mike Freelander MP", "party": "Australian Labor Party"},
{"name": "Hon Josh Frydenberg MP", "party": "Liberal Party of Australia"},
{"name": "Hon Andrew Gee MP", "party": "The Nationals"},
{"name": "Mr Steve Georganas MP", "party": "Australian Labor Party"},
{"name": "Mr Andrew Giles MP", "party": "Australian Labor Party"},
{"name": "Hon Dr David Gillespie MP", "party": "The Nationals"},
{"name": "Mr Ian Goodenough MP", "party": "Liberal Party of Australia"},
{"name": "Mr Patrick Gorman MP", "party": "Australian Labor Party"},
{"name": "Mr Luke Gosling OAM, MP", "party": "Australian Labor Party"},
{"name": "Mr Ross Hart MP", "party": "Australian Labor Party"},
{"name": "Mr Andrew Hastie MP", "party": "Liberal Party of Australia"},
{"name": "Hon Alex Hawke MP", "party": "Liberal Party of Australia"},
{"name": "Mr Chris Hayes MP", "party": "Australian Labor Party"},
{"name": "Hon Sarah Henderson MP", "party": "Liberal Party of Australia"},
{"name": "Mr Julian Hill MP", "party": "Australian Labor Party"},
{"name": "Mr Kevin Hogan MP", "party": "The Nationals"},
{"name": "Mr Luke Howarth MP", "party": "Liberal Party of Australia"},
{"name": "Hon Greg Hunt MP", "party": "Liberal Party of Australia"},
{"name": "Hon Ed Husic MP", "party": "Australian Labor Party"},
{"name": "Hon Steve Irons MP", "party": "Liberal Party of Australia"},
{"name": "Mr Stephen Jones MP", "party": "Australian Labor Party"},
{"name": "Hon Barnaby Joyce MP", "party": "The Nationals"},
{"name": "Hon Bob Katter MP", "party": "Katter's Australian Party"},
{"name": "Ms Ged Kearney MP", "party": "Australian Labor Party"},
{"name": "Ms Justine Keay MP", "party": "Australian Labor Party"},
{"name": "Hon Michael Keenan MP", "party": "Liberal Party of Australia"},
{"name": "Mr Craig Kelly MP", "party": "Liberal Party of Australia"},
{"name": "Hon Dr Mike Kelly AM, MP", "party": "Australian Labor Party"},
{"name": "Mr Matt Keogh MP", "party": "Australian Labor Party"},
{"name": "Mr Peter Khalil MP", "party": "Australian Labor Party"},
{"name": "Hon Catherine King MP", "party": "Australian Labor Party"},
{"name": "Ms Madeleine King MP", "party": "Australian Labor Party"},
{"name": "Ms Susan Lamb MP", "party": "Australian Labor Party"},
{"name": "Mr Andrew Laming MP", "party": "Liberal Party of Australia"},
{"name": "Hon Michelle Landry MP", "party": "The Nationals"},
{"name": "Mr Julian Leeser MP", "party": "Liberal Party of Australia"},
{"name": "Hon Dr Andrew Leigh MP", "party": "Australian Labor Party"},
{"name": "Hon Sussan Ley MP", "party": "Liberal Party of Australia"},
{"name": "Hon David Littleproud MP", "party": "The Nationals"},
{"name": "Mrs Nola Marino MP", "party": "Liberal Party of Australia"},
{"name": "Hon Richard Marles MP", "party": "Australian Labor Party"},
{"name": "Ms Emma McBride MP", "party": "Australian Labor Party"},
{"name": "Hon Michael McCormack MP", "party": "The Nationals"},
{"name": "Hon Dr John McVeigh MP", "party": "Liberal Party of Australia"},
{"name": "Mr Brian Mitchell MP", "party": "Australian Labor Party"},
{"name": "Mr Rob Mitchell MP", "party": "Australian Labor Party"},
{"name": "Hon Scott Morrison MP", "party": "Liberal Party of Australia"},
{"name": "Mr Ben Morton MP", "party": "Liberal Party of Australia"},
{"name": "Hon Shayne Neumann MP", "party": "Australian Labor Party"},
{"name": "Mr Llew O'Brien MP", "party": "The Nationals"},
{"name": "Mr Ted O'Brien MP", "party": "Liberal Party of Australia"},
{"name": "Hon Brendan O'Connor MP", "party": "Australian Labor Party"},
{"name": "Mr Ken O'Dowd MP", "party": "The Nationals"},
{"name": "Hon Kelly O'Dwyer MP", "party": "Liberal Party of Australia"},
{"name": "Ms Clare O'Neil MP", "party": "Australian Labor Party"},
{"name": "Ms Cathy O'Toole MP", "party": "Australian Labor Party"},
{"name": "Ms Julie Owens MP", "party": "Australian Labor Party"},
{"name": "Mr Tony Pasin MP", "party": "Liberal Party of Australia"},
{"name": "Mr Graham Perrett MP", "party": "Australian Labor Party"},
{"name": "Dr Kerryn Phelps AM, MP", "party": "Independent"},
{"name": "Hon Keith Pitt MP", "party": "The Nationals"},
{"name": "Hon Tanya Plibersek MP", "party": "Australian Labor Party"},
{"name": "Hon Christian Porter MP", "party": "Liberal Party of Australia"},
{"name": "Hon Melissa Price MP", "party": "Liberal Party of Australia"},
{"name": "Hon Christopher Pyne MP", "party": "Liberal Party of Australia"},
{"name": "Mr Rowan Ramsey MP", "party": "Liberal Party of Australia"},
{"name": "Hon Amanda Rishworth MP", "party": "Australian Labor Party"},
{"name": "Hon Stuart Robert MP", "party": "Liberal Party of Australia"},
{"name": "Ms Michelle Rowland MP", "party": "Australian Labor Party"},
{"name": "Ms Joanne Ryan MP", "party": "Australian Labor Party"},
{"name": "Ms Rebekha Sharkie MP", "party": "Centre Alliance"},
{"name": "Hon Bill Shorten MP", "party": "Australian Labor Party"},
{"name": "Hon Tony Smith MP", "party": "Liberal Party of Australia"},
{"name": "Hon Warren Snowdon MP", "party": "Australian Labor Party"},
{"name": "Ms Anne Stanley MP", "party": "Australian Labor Party"},
{"name": "Hon Michael Sukkar MP", "party": "Liberal Party of Australia"},
{"name": "Ms Meryl Swanson MP", "party": "Australian Labor Party"},
{"name": "Hon Angus Taylor MP", "party": "Liberal Party of Australia"},
{"name": "Hon Dan Tehan MP", "party": "Liberal Party of Australia"},
{"name": "Ms Susan Templeman MP", "party": "Australian Labor Party"},
{"name": "Hon Matt Thistlethwaite MP", "party": "Australian Labor Party"},
{"name": "Hon Alan Tudge MP", "party": "Liberal Party of Australia"},
{"name": "Ms Maria Vamvakinou MP", "party": "Australian Labor Party"},
{"name": "Mr Bert van Manen MP", "party": "Liberal Party of Australia"},
{"name": "Mr Ross Vasta MP", "party": "Liberal Party of Australia"},
{"name": "Mr Andrew Wallace MP", "party": "Liberal Party of Australia"},
{"name": "Mr Tim Watts MP", "party": "Australian Labor Party"},
{"name": "Mrs Lucy Wicks MP", "party": "Liberal Party of Australia"},
{"name": "Mr Andrew Wilkie MP", "party": "Independent"},
{"name": "Mr Josh Wilson MP", "party": "Australian Labor Party"},
{"name": "Mr Rick Wilson MP", "party": "Liberal Party of Australia"},
{"name": "Mr Tim Wilson MP", "party": "Liberal Party of Australia"},
{"name": "Mr Jason Wood MP", "party": "Liberal Party of Australia"},
{"name": "Hon Ken Wyatt AM, MP", "party": "Liberal Party of Australia"},
{"name": "Mr Tony Zappia MP", "party": "Australian Labor Party"},
{"name": "Mr Trent Zimmerman MP", "party": "Liberal Party of Australia"}
]`;
const subst = `: "$2"`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
如果不需要此表达式,可以在regex101.com中对其进行修改或更改。
jex.im可视化正则表达式: