kernelgpf Posted October 11, 2011 Share Posted October 11, 2011 I'm trying to grab all names (in: LNAME, FNAME, POSSIBLE INITIAL) in a bunch of text, I have this set of rules: /[^OWNER NAME].*([^0-9+][A-Z]{1}[^0-9+][a-z]+[^0-9+]\, [A-Z]{1}[^0-9+][a-z]+[^0-9+])/' What I'm trying to do is some names have "OWNER NAME" very recently in the last line or two before the name, and I -do not- want those. Only if that string isn't found in in the last line or two do I want it. Example of a name I would -not- want to collect: OWNER NAME (IF SAME, WRITE “SAMEâ€) ADDRESS (STREET, CITY, STATE, ZIP CODE) 5 Wu, Isabella [code] Example of returned strings matching current rules: Array ( [1] => Okulich, Kathern, [2] => Broadus, Raymond, Avery ) [EDIT: the reasons I account for no numbers is because it was pulling back home addresses. also, the pattern above simply doesn't work.] Quote Link to comment https://forums.phpfreaks.com/topic/248929-regex-how-to-ignore-a-literal-string/ Share on other sites More sharing options...
Psycho Posted October 11, 2011 Share Posted October 11, 2011 The "rules" as you have stated them are not specific enough to provide anything. Can you please provide a couple examples of the inputs and the expected outputs? Quote Link to comment https://forums.phpfreaks.com/topic/248929-regex-how-to-ignore-a-literal-string/#findComment-1278395 Share on other sites More sharing options...
kernelgpf Posted October 12, 2011 Author Share Posted October 12, 2011 bump, need help fast!! Quote Link to comment https://forums.phpfreaks.com/topic/248929-regex-how-to-ignore-a-literal-string/#findComment-1278481 Share on other sites More sharing options...
Psycho Posted October 12, 2011 Share Posted October 12, 2011 Well, I already stated that I did not understand your question as asked. The fact that no one else has responded probably means no one else understood it either. Why don't you try doing what I asked, give some examples of the input you wouold have and the expected output. Quote Link to comment https://forums.phpfreaks.com/topic/248929-regex-how-to-ignore-a-literal-string/#findComment-1278497 Share on other sites More sharing options...
salathe Posted October 12, 2011 Share Posted October 12, 2011 Your regex starts like /[^OWNER NAME] This is not doing what you think it is! It's actually just checking for "a single character that is not in the set of characters O, W, N, E, R, <space>, A and M". You probably want something like /^(?!OWNER NAME) which makes sure that the line doesn't start with "OWNER NAME". For help on the (?!...) search on "regex lookaround". Quote Link to comment https://forums.phpfreaks.com/topic/248929-regex-how-to-ignore-a-literal-string/#findComment-1278521 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.