473,320 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Search Operation with Delimiters

I have the below scenario
Search Function (Could be Fwd/Reverse Direction)

Ex: 2-6-281651 (Start-Offset-Value) or 2-6-"281-651"

I was able to create code based on the split delimiter as (-), but if my search string has - in it, how can we handle.

I can change the delimiter, but what if the new delimiter is part of the string, i can make sure that the value is in "",

I am trying to create a generic solution, with out any limitations
Nov 16 '12 #1
4 2156
Rabbit
12,516 Expert Mod 8TB
You could use your "surround it in quotes" solution. I'm unsure what your question is.
Nov 17 '12 #2
bvdet
2,851 Expert Mod 2GB
You would not need the quotes using a regex solution. See if this works for you:
Expand|Select|Wrap|Line Numbers
  1. import re
  2.  
  3. patt = re.compile(r"(\d+)-(\d+)-(.+)")
  4.  
  5. s ='2-6-281-651'
  6.  
  7. m = patt.match(s)
  8. if m:
  9.     print m.group(1)
  10.     print m.group(2)
  11.     print m.group(3)
  12.  
  13. s ='122-61-281651'
  14.  
  15. m = patt.match(s)
  16. if m:
  17.     print m.group(1)
  18.     print m.group(2)
  19.     print m.group(3)
Nov 17 '12 #3
bvdet
2,851 Expert Mod 2GB
I forgot about the maxsplit argument.
Expand|Select|Wrap|Line Numbers
  1. >>> s = '2-6-281-651'
  2. >>> s.split('-',2)
  3. ['2', '6', '281-651']
  4. >>> 
Nov 22 '12 #4
dwblas
626 Expert 512MB
Use a delimiter that won't be in any string like *#@.
Nov 23 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: spike | last post by:
Im writing a program to search for a string in a binary file. And it works. The problem is: It is sooo slow! how can i make it faster? It takes 27 seconds just to search a 5 meg file. I guess it...
5
by: Jim | last post by:
Hello, I am working on a small windows application for a client, and as one of the functions they want a search that will let them enter a search string, then search a directory for all flies...
2
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. Is there a way to start, pause and resume a recurrsive search exactly where you left off, say in the registry programmatically? -- Michael Bragg,...
33
by: Bertram Trabant | last post by:
Hello, Im working on a little LAN game in the style of old text-only MUD's and would need to find a way to search for a string in a text file (for example for usernames). I know it works in the way...
6
by: flash | last post by:
write a program that manipulates arrays of integers. The main program should call three functions: Insert, Delete, and Search. The Insert function should call a function Sort that sorts the array. ...
9
by: Rick | last post by:
I have a large list of objects where each object has a unique (non-overlapping) date range. The list is sorted chronologically. What is the most efficient way to search this list for a single...
9
by: Owen Zhang | last post by:
I have a file loaded into virtual memory space by mmap. I need to search some key word inside the memory opened by mmap. What is the best and efficient way to do?
2
by: parasuram | last post by:
Hi friends ............. this is a question regarding the data structures trees Pleas post it if possible with in 2 days I will thankful if some body could help doing this. Operating...
64
by: Mika | last post by:
Hello, we understand you guys may be able to help. We have a page which has been working great for over a year and gets many hits. However recently something got changed that we cannot seem to...
1
by: ajith3000 | last post by:
hi everyone,please help me .i'm a newbie see i have a form in that i have following controls .combobox .textbox .listview the combobox contains all the column names of listview like...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.