मैं इस है कि तुम क्या आवश्यकता है लगता है:
\w+\s?(\d{1,2})?(:\d{1,2})?([-–]\d{1,2})?(,\s\d{1,2}[-–]\d{1,2})?
अनुमान:
- संख्या के सेट में हमेशा से रहे हैं 1 या 2 अंक
- पानी का छींटा टिप्पणी के साथ निम्नलिखित
-
और –
नीचे है regex के दोनों मिलान हो जाएगा:
"
\w # Match a single character that is a “word character” (letters, digits, and underscores)
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
\s # Match a single character that is a “whitespace character” (spaces, tabs, and line breaks)
? # Between zero and one times, as many times as possible, giving back as needed (greedy)
( # Match the regular expression below and capture its match into backreference number 1
\d # Match a single digit 0..9
{1,2} # Between one and 2 times, as many times as possible, giving back as needed (greedy)
)? # Between zero and one times, as many times as possible, giving back as needed (greedy)
( # Match the regular expression below and capture its match into backreference number 2
: # Match the character “:” literally
\d # Match a single digit 0..9
{1,2} # Between one and 2 times, as many times as possible, giving back as needed (greedy)
)? # Between zero and one times, as many times as possible, giving back as needed (greedy)
( # Match the regular expression below and capture its match into backreference number 3
[-–] # Match a single character present in the list “-–”
\d # Match a single digit 0..9
{1,2} # Between one and 2 times, as many times as possible, giving back as needed (greedy)
)? # Between zero and one times, as many times as possible, giving back as needed (greedy)
( # Match the regular expression below and capture its match into backreference number 4
, # Match the character “,” literally
\s # Match a single character that is a “whitespace character” (spaces, tabs, and line breaks)
\d # Match a single digit 0..9
{1,2} # Between one and 2 times, as many times as possible, giving back as needed (greedy)
[-–] # Match a single character present in the list “-–”
\d # Match a single digit 0..9
{1,2} # Between one and 2 times, as many times as possible, giving back as needed (greedy)
)? # Between zero and one times, as many times as possible, giving back as needed (greedy)
"
और यहाँ php में इसके उपयोग के कुछ उदाहरण हैं:
if (preg_match('/\w+\s?(\d{1,2})?(:\d{1,2})?([-–]\d{1,2})?(,\s\d{1,2}[-–]\d{1,2})?/', $subject)) {
# Successful match
} else {
# Match attempt failed
}
किसी दिए गए स्ट्रिंग में सभी मैचों की एक सरणी प्राप्त करें
preg_match_all('/\w+\s?(\d{1,2})?(:\d{1,2})?([-–]\d{1,2})?(,\s\d{1,2}[-–]\d{1,2})?/', $subject, $result, PREG_PATTERN_ORDER);
$result = $result[0];
तो यह मेल खाना चाहिए भले ही यह सिर्फ किताब का नाम हो? क्या आपके पास पुस्तकों की एक सूची है जो इसे मेल खाना चाहिए? अन्यथा यह सिर्फ हर शब्द से मेल खाता होगा। – JJJ
बस किसी भी शब्द से मेल खाते हैं, मेरे लिए असली समस्या इतनी सारे वैकल्पिक भागों में है। – Dziamid