| 
			
			 | 
		#1 | 
| 
			
			
			
			 Junior Member 
			
			![]() Posts: 5 
				Karma: 10 
				Join Date: Mar 2009 
				
				
				
				Device: Sony PRS-500, Treo 755p, REB 1100, eBookman 911 
				
				
				 | 
	
	
	
		
		
			
			  Hey guys,I'm trying to edit some bulk data using regex and I'm having trouble matching groups. I wasn't paying attention when importing, so now I have author fields that can include author, author and series, or author, series, and series number. I'm trying to match series and seriesnum out of the author field and send them to the appropriate places using the bulk meta edit tool. the expression I'm using right now is: ([a-zA-Z.\ ]+) (\-) ([\ \w]*) (\d+) which matches "A. J. Author - Series of Books 01" I can then use \3 to send "Series of Books" to series and \4 to send "01" to seriesnum. The problem is when it finds an author field with just an author and no series number or series (i.e. "A. J. Author"). In that case \3 and \4 also match "A.J. Author" though it seems they should be blank instead since they shouldn't exist. Can anyone help me figure this out?  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#2 | 
| 
			
			
			
			 Addict 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 315 
				Karma: 1645952 
				Join Date: Jun 2012 
				
				
				
				Device: none 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			Maybe filter the books in the main window first to include only books with a "-" in the author, then run the regex on only that set?
		 
		
	
		
		
		
		
		
		
		
		
		
		
	
	 | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#3 | 
| 
			
			
			
			 Ex-Helpdesk Junkie 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421 
				Karma: 85400180 
				Join Date: Nov 2012 
				Location: The Beaten Path, USA, Roundworld, This Side of Infinity 
				
				
				Device: Kindle Touch fw5.3.7 (Wifi only) 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			Why are you escaping the dashes and spaces? 
		
	
		
		
		
		
		
		
		
		
		
		
	
	As for your mysterious problem, calibre replaces one field with another, after trying the regex replacement. ![]() Since the replacement failed, the fields are copied over as-is. This has tripped me up too.  
		 | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#4 | 
| 
			
			
			
			 Grand Sorcerer 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525 
				Karma: 8065948 
				Join Date: Jan 2010 
				Location: Notts, England 
				
				
				Device: Kobo Libra 2 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			@eschwartz: FWIW (which isn't much) the way I mentally handle this problem is to remind myself that a replacement only occurs if the entire search pattern successfully matches against the source, and that in that case only the matched segment of the source is replaced. I often find myself sticking anchors and .*s in odd places to be sure that the pattern matches the entire source.
		 
		
	
		
		
		
		
		
		
		
		
		
		
	
	 | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
![]()  | 
            
        
    
| Tags | 
| bulk edit metadata, meta data, regex | 
| Thread Tools | Search this Thread | 
            
  | 
    
			 
			Similar Threads
		 | 
	||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| bulk meta and series info | gabby98 | Calibre | 11 | 12-21-2013 01:48 PM | 
| Regex help: Edit Meta Search & Replace: Pad with zero | _noel_ | Calibre | 4 | 11-26-2012 05:31 PM | 
| Bulk Edit of comments using regex | PeterT | Library Management | 2 | 07-25-2012 09:10 AM | 
| Bulk metada edit error trying to edit tags | Purple Lady | Calibre | 8 | 02-17-2011 07:09 PM | 
| Bulk Meta Data Edit Resetting Custom Field | toomuchreading | Calibre | 8 | 10-22-2010 11:19 PM |