Question: I have to match document ID's in free-form text. The text is already split into sentences or lines and there is at most one ID number in each line. The ID's can have different formats and can include spaces, so in general I want to match:

* a word indicating that an ID follows (let's assume it's always "ID")
* some whitespace/punctuation (let's assume it's either at least one space or exactly one colon surrounded with optional spaces)
* any sequence of letters, digits, slashes and hyphens, optionally containing spaces, but (and now's the catch) **there's no sequence "digit-space-letter" in it** (because usually this means that the letter belongs to a word that follows the ID; a sequence "letter-space-letter" is ambiguous, but usually happens inside an ID, so I want it to match)

So for example, I want to match:

```
ID: 1
ID 1/1
ID : 1/A
ID     AAA X1
ID :B/B
ID 1/ A
ID 1 /A
ID 1 /A/ AA
ID 1 /A /AA
ID AA 123
ID AA 123 123
ID AA/123 123

```

but not

```
ID 1 AAA
ID 1/1 AAA

```

In the above two cases, I want to match only `ID 1` and `ID 1/1` respectively.

This is what I got so far, it doesn't work though:

`ID(\s+|\s*:\s*)(?:[\p{L}0-9/-]*\s)*[0-9/-][\p{L}0-9/-]*`

Answer: 
Okay, thanks to hints I finally figured it out on my own:

```
ID(?: +| *: *)((?:[0-9](?:\s+(?![a-zA-Z]))?|[A-Za-z/]\s*)*)

```

After every non-blank character, I attempt to match spaces, but after a digit I match optional spaces under a condition that those spaces are not followed by a letter.
Here's my edited solution : 

You can use two regexs : 

First : 

```
ID[\s:]+[\da-zA-Z\s/-]*

```

It matches `ID` followed by spaces or comas, with at least one of these.

Then the `[\da-zA-Z\s/-]*` part will match any sequence of digits, letters, spaces, slashes and hyphens. 

This will make sure your setence follows the wanted pattern.

The additional condition is done with a second regex : 

```
\d [a-zA-Z]

```

If this second regex is matched, then your sentence doesn't respect the no sequence "digit-space-letter" condition, and should be rejected.