0

Can someone help me to find the job id from the text below:

$search_string = '/jobs/17 has no compatible crew with sufficient capacity (job: 304390)';

I have tried the following but did not have any luck:

preg_match("/\[job: ([A-Za-z\/]+)\]/", $search_string, $match);
print_r($match) --showing empty
2
  • 1
    Does this answer your question? Regex for matching certain numbers of digits Commented Jan 4, 2023 at 11:42
  • 1
    Why do you have \[ and \]? There don't appear to be any []s in your string. Also [A-Za-z\/] would look for alpha characters or a backslash, what do you want to match, the 17, the 30, or both? Commented Jan 4, 2023 at 11:46

1 Answer 1

2

You should match parenthesis instead, and capture 1 or more digits. Then you can get the group 1 value:

\(job: (\d+)\)/

Example

$search_string = '/jobs/17 has no compatible crew with sufficient capacity (job: 304390)';
if (preg_match("/\(job: (\d+)\)/", $search_string, $match)) {
    print_r($match[1]);
}

Output

304390
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.