Match a pattern containing multiple subpatern in different order

In Python with Re library, I try to match a char structur with this synopsis:

[n|new|newgame] <name> [code=<code>] [type=<type>] [licence=<licence>] [url=<url>]

But code, type, licence, and url statements could appear in any order not necessary this one. Or could also not appear at all.

For the moment, I have the following code:

import re

# Adjusted regex pattern to match up to 'url' without consuming the entire line if 'url' is absent
addNewGamepattern = r'(n|new|newgame)s+(?P<name>S+)s+' 
                    r'(?:code=(?P<code>[a-zA-Z0-9]*)s*)?' 
                    r'(?:type=(?P<type>fps|mmorpg|rpg)s*)?' 
                    r'(?:licence=(?P<licence>mit|gpl|cc|copyright)s*)?' 
                    r'(?:url=(?P<url>S+)s*)?'

# List of test strings
test_strings = [
    "newgame MyGame code=ABC type=fps licence=mit url=http://example.com",
    "n MyGame type=rpg code=123",
    "new MyGame url=http://example.com code=XYZ licence=gpl type=mmorpg",
    "newgame AnotherGame code=DEF licence=cc type=mmorpg",
    "newgame GameWithoutParameters"
]

# Function to test the pattern with each string
def test_pattern(pattern, strings):
    for string in strings:
        match = re.match(pattern, string)
        if match:
            print(f"String: '{string}'")
            print("Match found!")
            print(f"Game name: {match.group('name')}")
            print(f"Code: {match.group('code') if match.group('code') else 'Not specified'}")
            print(f"Type: {match.group('type') if match.group('type') else 'Not specified'}")
            print(f"Licence: {match.group('licence') if match.group('licence') else 'Not specified'}")
            print(f"URL: {match.group('url') if match.group('url') else 'Not specified'}")
            print()
        else:
            print(f"String: '{string}'")
            print("No match found.")
            print()

# Testing the pattern with the test strings
test_pattern(addNewGamepattern, test_strings)

But it doesn’t work yet as I expect. Cause here is it output:

String: 'newgame MyGame code=ABC type=fps licence=mit url=http://example.com'
Match found!
Game name: MyGame
Code: ABC
Type: fps
Licence: mit
URL: http://example.com

String: 'n MyGame type=rpg code=123'
Match found!
Game name: MyGame
Code: Not specified
Type: rpg
Licence: Not specified
URL: Not specified

String: 'new MyGame url=http://example.com code=XYZ licence=gpl type=mmorpg'
Match found!
Game name: MyGame
Code: Not specified
Type: Not specified
Licence: Not specified
URL: http://example.com

String: 'newgame AnotherGame code=DEF licence=cc type=mmorpg'
Match found!
Game name: AnotherGame
Code: DEF
Type: Not specified
Licence: cc
URL: Not specified

String: 'newgame GameWithoutParameters'
No match found.

As you can see, the elements who are not following theire order are just ignored.

The question

How to match the optional parameters no matter their order?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật